这是客户端调用Post的方法
public static string HttpPost1(string url,string JsonData)
{
Encoding encoding = Encoding.UTF8;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "Post";
request.Accept = "text/html,application/xhtml+xml,*/*";
request.ContentType = "application/json";
var byteData = Encoding.UTF8.GetBytes(JsonData);
var length = byteData.Length;
request.ContentLength = length;
var writer = request.GetRequestStream();
writer.Write(byteData, 0, length);
writer.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
string url_p = "http://localhost:61657/api/test";
this.text_Res.Text = HttpPost2(url_p, json_g);
下面是服务端对Post的定义
public Getres Post(string json_get)
{
xxxxxxxx
}
为什么老是会报错405啊.....不理解哪个环节出了问题