facebook页面墙帖上的错误请求(getResponse())

本文关键字:请求 错误 getResponse facebook | 更新日期: 2023-09-27 18:21:41

当我试图张贴到页面墙上时,收到一个错误代码400"错误请求"。这是代码:

public string Post(Int64 Id)
{
    using (DataContext db = new DataContext())
    {
        var msg = (from t1 in db.Table1
                   join t2 in db.Table2 on t1.UserId equals t2.UserId
                   where t1.Id == Id
                   select new {t1, t2}).FirstOrDefault();
        var url = "https://graph.facebook.com/" + msg.t2.Table3.FBPageId + "/feed";
        AppendQueryString(ref url, "access_token", msg.t2.Table3.FacebookAuth);
        AppendQueryString(ref url, "privacy", "{'"value'": '"EVERYONE'"}");
        AppendQueryString(ref url, "message", msg.t1.Message);
        var webRequest = WebRequest.Create(url);
        webRequest.ContentType = "application/x-www-form-urlencoded";
        webRequest.Method = "POST";
        byte[] bytes = System.Text.Encoding.ASCII.GetBytes(url);
        webRequest.ContentLength = bytes.Length;
        System.IO.Stream os = webRequest.GetRequestStream();
        os.Write(bytes, 0, bytes.Length);
        os.Close();
        try
        {
            var webResponse = webRequest.GetResponse();
        }
        catch (Exception ex)
        {
            return ex.Stacktrace;
        }
    return "Something random";             
}  

代码在catch中的返回处结束(webRequest.GetResponse();失败)。

AppendQueryString只是一个生成查询字符串(?或&)并返回新的url的方法。

我做错什么了吗?

facebook页面墙帖上的错误请求(getResponse())

我不得不将"基本"url和参数一分为二,并将参数放入byte[] bytes = System.Text.Encoding.ASCII.GetBytes(parameters);中,并将url保留在var webRequest = WebRequest.Create(url);

现在工作