我需要使用POST方法将数据发送到CGI脚本。如果我尝试在捕获小提琴手的情况下运行代码,则可以正常工作;如果我关闭小提琴手,则无法正常工作。为什么会有这种奇怪的行为?
脚本cgi位于发送SMS的sms机器上。如果我在运行外部提琴手进程的情况下从Visual Studio 2019运行我的代码,则可以正确获得以下响应:errno=0&desc=SMS Queued&SmsIndex=4
如果我关闭提琴手并运行代码,则会收到错误:errno=2&desc=Destination number missing
。
我还发现,如果我停止fiddler捕获http流量,并且在我的代码中将http://localhost:8888上的WebProxy设置为有效,但是,如果我关闭fiddler,则该代理将关闭并且我的代码不再起作用。
我需要发布没有代理的数据,该怎么办?
我尝试使用.NET Framework对象和RestSharp:相同的问题! 这是我的.NET Framework代码:
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 Framework代码:
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();
答案 0 :(得分:0)
我通过使用TcpClient和NetworkStream解决了