大家好,我正在尝试使用 HttpWebRequest 方法将打开的图形操作发布到 facebook。
这是我的请求方法
public static string RequestUrl(string action, String HTTPMETHOD, dynamic postdata = null)
{
string results = "";
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(action);
if (HTTPMETHOD == "GET")
{
req.Method = WebRequestMethods.Http.Get;
}
else if (HTTPMETHOD == "POST")
{
ASCIIEncoding encoding = new ASCIIEncoding();
req.Method = WebRequestMethods.Http.Post;
byte[] data = encoding.GetBytes(postdata.sneaqer);
req.ContentLength = data.Length;
req.ContentType = "application/x-www-form-urlencoded";
Stream newStream = req.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
}
else if (HTTPMETHOD == "DELETE")
{
req.Method = "DELETE";
ASCIIEncoding encoding = new ASCIIEncoding();
}
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
results = sr.ReadToEnd();
sr.Close();
}
catch (Exception ex)
{
Error.Log("ERROR: Common.cs requestUrl() " + ex.Message + " " + action);
}
return results;
}
这是我迄今为止尝试过的
var url = "https://graph.facebook.com/" + personFacebookUserId + "/verbNamespace:follow";
dynamic parameters = new System.Dynamic.ExpandoObject();
parameters.person = "http:" + Configuration.getConfigValue("SiteUrl") + "OG/OpenGraphAction.aspx?type=follow&facebookProfilePicture=" + friendFacebookUserId;
string result = Common.RequestUrl(url, "POST", parameters);
我得到一个错误服务器返回了一个错误的请求。我认为问题在于我传递参数的方式。人是对象,跟随是行动。
谢谢你的帮助。