我需要发送数据到一个cgi脚本的POST方法。如果我在打开小提琴捕捉的情况下尝试我的代码,它就能工作,如果我关闭小提琴,它就不能工作。为什么会有这种奇怪的行为?
脚本cgi位于发送SMS的sms机器上。如果我在运行外部fiddler进程的情况下从Visual Studio2019运行我的代码,我会正确地得到这个响应:errno=0&desc=SMS Queued&SmsIndex=4
如果我关闭fiddler并运行我的代码,我会得到错误:errno=2&desc=Destination number missing
。
我还发现,如果我阻止fiddler捕获http流量,并且在我的代码中设置了http://localhost:8888 it works...BUT上的WebProxy,如果我关闭fiddler,代理就会关闭,我的代码就不再工作。
我需要在没有代理的情况下发布数据,我该怎么做?
我用.NET框架对象和RestSharp都试过了:同样的问题!这是我的代码.NET框架代码:
Dictionary<string,string> smsData = new Dictionary<string, string>{
{ "num", number },
{ "text", text },
{ "Push", push.ToString() },
{ "Pwd", password },
};
FormUrlEncodedContent formUrlEncodedContent = new FormUrlEncodedContent(smsData);
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "http://" + ip + "/smssend.cgi");
httpRequestMessage.Content = formUrlEncodedContent;
HttpResponseMessage res = _httpClient.SendAsync(httpRequestMessage).Result;
return res.Content.ReadAsStringAsync().Result;
这是我的带有RestSharp库的.NET框架代码:
RestClient client = new RestClient("http://" + ip + "/smssend.cgi");
RestRequest request = new RestRequest("", Method.POST);
request.AddParameter("num", number);
request.AddParameter("text", text);
request.AddParameter("Push", push.ToString());
request.AddParameter("Pwd", password);
RestResponse response = (RestResponse) client.Execute(request);
return response.Content.ToString();
https://stackoverflow.com/questions/56216611
复制相似问题