C#winform-post请求
各位大侠,我现在是想向http://dwz.cn/create.php,发送POST请求,发送的内容是:www.baidu.com
但是返回一直是错误的,请指点。
string postDataStr = "www.baidu.com";
string Url = "http://dwz.cn/create.php";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.CookieContainer = new CookieContainer();
request.Method = "POST";
request.ContentLength = postDataStr.Length;
Stream myRequestStream = request.GetRequestStream();
StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));
myStreamWriter.Write(postDataStr);
myStreamWriter.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString = myStreamReader.ReadToEnd();
MessageBox.Show(retString.ToString());
请求:向dwz.cn/create.php发送post请求,发送数据包括url=www.baidu.com
status!=0 出错,查看err_msg获得错误信息(UTF-8编码)
成功,返回生成的短网址 tinyurl字段
请指点下为何我返回的信息是错误呢,请高手指点。
------解决方案--------------------
request.ContentType="application/x-www-form-urlencoded";
------解决方案--------------------
你提交的格式不正确,没有longurl
------解决方案--------------------
你在浏览器里面的测试url是什么?表单名称完全一样才可以
------解决方案--------------------
string postDataStr = "url=www.baidu.com&alias=&access_type=web";
返回
{"longurl":"www.baidu.com","status":0,"tinyurl":"http:\/\/dwz.cn\/yes"}表示成功