本帖最后由 sk沧海一粟 于 2019-12-8 01:53 编辑
试了一下 服务器显示的是404
你控制器没写对或者路由没写对
winform端 可以把以下代码封装成POST函数 下次直接用
[C#] 纯文本查看 复制代码 //shareFile();
//地址
string url = "https://www.fengkuangmaijia.com/api.php";
//post数据
string postDataStr = "action=getcode&tel=17710398888";
HttpWebRequest GetVerificationCode = (HttpWebRequest)WebRequest.Create(url);
//POST or GET
GetVerificationCode.Method = "POST";
//编码
GetVerificationCode.Headers["Charset"] = "UTF-8";
//数据类型 如果不是application/x-www-form-urlencoded 或者 multipart/form-data PHP端$_POST可能获取不到
//json的话 填写application/json
GetVerificationCode.ContentType = "application/x-www.form-urlencoded";
GetVerificationCode.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);
Stream myRequestStream = GetVerificationCode.GetRequestStream();
StreamWriter myStreamWriter = new StreamWriter(myRequestStream);
myStreamWriter.Write(postDataStr);
myStreamWriter.Close();
HttpWebResponse response = (HttpWebResponse)GetVerificationCode.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString1 = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close(); |