我读了this documentation并使用了那里给出的代码。除了我试图发送的消息外,一切正常。墙上的消息似乎是空的。
accessUrl是正确的,因此发送消息。
SendHttpRequest(accessUrl, "message = This is a test", HttpMethodsEnum.POST);
这是我使用的方法
public virtual string SendHttpRequest(string Url, string Request, HttpMethodsEnum MethodType = HttpMethodsEnum.POST)
{
HttpWebRequest webRequest = null;
StreamWriter requestWriter = null;
string responseData = "";
webRequest = System.Net.WebRequest.Create(Url) as HttpWebRequest;
webRequest.Method = MethodType.ToString();
webRequest.ServicePoint.Expect100Continue = false;
webRequest.UserAgent = "[You user agent]";
webRequest.Timeout = 20000;
if (MethodType == HttpMethodsEnum.POST)
{
webRequest.ContentType = "application/x-www-form-urlencoded";
requestWriter = new StreamWriter(webRequest.GetRequestStream());
try
{
requestWriter.Write(Request);
}
catch
{
throw;
}
finally
{
requestWriter.Close();
requestWriter = null;
}
}
StreamReader streamReader = null;
try
{
streamReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
responseData = streamReader.ReadToEnd();
}
catch
{
throw;
}
finally
{
webRequest.GetResponse().GetResponseStream().Close();
streamReader.Close();
streamReader = null;
}
return responseData;
}
答案 0 :(得分:0)
我不相信"message = This is a test"
是post参数的正确格式。确保使用您的语言这是正确的。我认为格式更复杂。见http://geekswithblogs.net/rakker/archive/2006/04/21/76044.aspx