HttpWebResponse的Post发包问题 7C

c#中用HttpWebResponse类进行Post发包,发包的数据格式是multipart/form-data;
有两个网址:
http://hpcgi2.nifty.com/tono-k/bbs/bbs.cgi
http://handaipfc.com/cgi-bin/imgboard.cgi
我已经写好了发包的方法,测试第一地址是发包成功的,但是对第二个地址却不成功,不知道什么原因,有没有高手帮忙看一下.
发包的数据:
-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="bbsaction"

post

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="page"

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="view_mode"

as_cgi_defined

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="blood"

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="parent"

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="prebbsaction"

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="amode"

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="p1"

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="p2"

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="target"

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="target_no"

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="sf"

針つゆシ灰み

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="onetime_token"

aSB2BUxsBU

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="optB"

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="body"

昔を追憶する

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="name"

昔を追憶する

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="subject"

昔を追憶する

-----------------------------8d3bb8669ffe4f1
Content-Disposition: form-data; name="img"; filename=""
Content-Type: application/octet-stream

-----------------------------8d3bb8669ffe4f1--

6个回答

你的地址没有,你的检查代码看下做了什么现在。不是自己用浏览器提交一次,看http头都包含了什么,如cookie之类,自定义其他的数据什么的,如防止crsf的token之类的

shengyueai
云鹤翔天 发送的数据有Token和Cookie,都发送了
接近 4 年之前 回复

private static string HttpPostTest(string url, int timeOut, NameValueCollection stringDict)
{
string responseContent;
var memStream = new MemoryStream();
var webRequest = (HttpWebRequest)WebRequest.Create(url);
// 边界符

var boundary = "---------------" + DateTime.Now.Ticks.ToString("x");
// 边界符

var beginBoundary = Encoding.ASCII.GetBytes("--" + boundary + "\r\n");
var endBoundary = Encoding.ASCII.GetBytes("--" + boundary + "--\r\n");

        // 设置属性  
        webRequest.Method = "POST";
        webRequest.Timeout = timeOut;
        webRequest.ContentType = "multipart/form-data; boundary=" + boundary;
        memStream.Write(beginBoundary, 0, beginBoundary.Length);
        // 写入字符串的Key  
        var stringKeyHeader = "\r\n--" + boundary +
                               "\r\nContent-Disposition: form-data; name=\"{0}\"" +
                               "\r\n\r\n{1}\r\n";

        foreach (byte[] formitembytes in from string key in stringDict.Keys
                                         select string.Format(stringKeyHeader, key, stringDict[key])
                                             into formitem
                                             select Encoding.UTF8.GetBytes(formitem))
        {
            memStream.Write(formitembytes, 0, formitembytes.Length);
        }

        // 写入最后的结束边界符  
        memStream.Write(endBoundary, 0, endBoundary.Length);

        webRequest.ContentLength = memStream.Length;
        string sss = System.Text.Encoding.Default.GetString(memStream.ToArray());
        var requestStream = webRequest.GetRequestStream();

        memStream.Position = 0;
        var tempBuffer = new byte[memStream.Length];
        memStream.Read(tempBuffer, 0, tempBuffer.Length);
        memStream.Close();

        requestStream.Write(tempBuffer, 0, tempBuffer.Length);
        requestStream.Close();

        var httpWebResponse = (HttpWebResponse)webRequest.GetResponse();

        using (var httpStreamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.GetEncoding("shift_jis")))
        {
            responseContent = httpStreamReader.ReadToEnd();
        }

        httpWebResponse.Close();
        webRequest.Abort();
        return responseContent;
    }

private static string HttpPostTest(string url, string boundary, string postData, string cookie)
{
string responseContent;
var webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Headers[HttpRequestHeader.Cookie] = cookie;
webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
webRequest.Method = "POST";
webRequest.Timeout = 600000;
webRequest.ContentType = "multipart/form-data; boundary=" + boundary;

byte[] buffer = Encoding.UTF8.GetBytes(postData);
webRequest.ContentLength = buffer.Length;
webRequest.GetRequestStream().Write(buffer, 0, buffer.Length);
var httpWebResponse = (HttpWebResponse)webRequest.GetResponse();
using (var httpStreamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.GetEncoding("shift_jis")))
{
responseContent = httpStreamReader.ReadToEnd();
}
httpWebResponse.Close();
webRequest.Abort();
return responseContent;
}


请求头
POST /cgi-bin/imgboard.cgi HTTP/1.1
Host: handaipfc.com
Connection: keep-alive
Content-Length: 1965
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Origin: http://handaipfc.com
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarybMSInkSagMemRRQm
Referer: http://handaipfc.com/cgi-bin/imgboard.cgi
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.8


第二个地址却不成功,第二个地址是哪个?提示什么?

解决自己解决了,编码问题,要换成日语的,UTF8不行

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Python+OpenCV计算机视觉

Python+OpenCV计算机视觉

[vb.net]HttpWebResponse的编码问题——GB2312乱码

我想用这段代码登录获取cookie,然后再访问用户页面,这一部分工作正常。可是如果遇到GB2312编码的网页就会出现乱码。请高手指点,万分感谢! 另:选这个网址仅供说明只用,没有别的意思。 ``` Imports System.Net Imports System.IO Imports System.Text Public Class Form1 Const ConnectURL = "http://www.guqu.net/User/User_ChkLogin.asp" Const HomeURL = "http://www.guqu.net/" Private Function RegularPage(ByVal URL As String, ByVal CookieJar As CookieContainer) As String Dim reader As StreamReader Dim Request As HttpWebRequest = HttpWebRequest.Create(URL) Request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14" Request.AllowAutoRedirect = False Request.CookieContainer = CookieJar Dim Response As HttpWebResponse = Request.GetResponse() reader = New StreamReader(Response.GetResponseStream()) Return reader.ReadToEnd() Response.Close() End Function Private Sub LogonPage(ByVal URL As String, ByRef CookieJar As CookieContainer, ByVal PostData As String) Dim reader As StreamReader Dim Request As HttpWebRequest = HttpWebRequest.Create(URL) Request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14" Request.CookieContainer = CookieJar Request.AllowAutoRedirect = False Request.ContentType = "application/x-www-form-urlencoded" Request.Method = "POST" Request.ContentLength = PostData.Length Dim requestStream As Stream = Request.GetRequestStream() Dim postBytes As Byte() = Encoding.ASCII.GetBytes(PostData) requestStream.Write(postBytes, 0, postBytes.Length) requestStream.Close() Dim Response As HttpWebResponse = Request.GetResponse() For Each tempCookie In Response.Cookies CookieJar.Add(tempCookie) Next reader = New StreamReader(Response.GetResponseStream()) Response.Close() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim CookieJar As New CookieContainer Dim PostData As String Try 'Logon PostData = "UserName=abc&UserPassword=abcdef&CheckCode=173872&ComeUrl=http%3A%2F%2Fwww.guqu.net%2F&Login.x=30&Login.y=13&Login=+%B5%C7+%C2%BC+" LogonPage(ConnectURL, CookieJar, PostData) 'Homepage Dim Sw As StreamWriter = File.CreateText("E:\response.html") Sw.Write(RegularPage(HomeURL, CookieJar)) Sw.Close() RichTextBox1.AppendText(RegularPage(HomeURL, CookieJar)) Catch ex As Exception MsgBox(ex.Message.ToString) End Try End Sub End Class ```

C# HttpWebResponse如何获取response body的HEX格式的数据?

``` public static string Post(string url, string content) { string result = ""; #region 添加Post 参数 byte[] data = Encoding.UTF8.GetBytes(content); try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Method = "POST"; req.KeepAlive = false; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = data.Length; Stream reqStream = req.GetRequestStream(); reqStream.Write(data, 0, data.Length); reqStream.Close(); #endregion HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); Stream stream = resp.GetResponseStream(); //获取响应内容 using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) { result = reader.ReadToEnd(); req.Abort(); } return result; } return ""; } ``` 请问这个代码如何修改得到HEX数据?

要保存 httpwebresponse里面的字节流怎么保存 ?

要保存 httpwebresponse里面的字节流怎么保存 ?

通过HttpWebRequest向服务器Post数据的问题

工作上需要通过http协议往服务器post一条json字符串,服务器会返回成功或者故障信息,网络上找了些HttpWebRequest例子,都遇到同一种现象,相同的代码,如果我电脑打开Fiddler 4软件,执行结果能够成功,但我关闭Fiddler 4情况下,返回提示信息是“发送数据不能为空”。 不知道问题的原因,请求帮助,谢谢 贴一段代码,c# public static string HttpPost(string url, string param) { byte[] byteArray = Encoding.UTF8.GetBytes(param); HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Method = "POST"; webRequest.ContentType = "text/xml;charset=UTF-8"; webRequest.ContentLength = byteArray.Length; Stream newStream = webRequest.GetRequestStream(); newStream.Write(byteArray, 0, byteArray.Length); newStream.Close(); HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse(); StreamReader php = new StreamReader(response.GetResponseStream(), Encoding.UTF8); string phpend = php.ReadToEnd(); return phpend; }

关于winform调用WebAPI,使用Post传参的问题

在WEBAPI那里,Post大概是这么设计的 ``` public string Post(Student stu) ``` 要传入的是个类。那么如何在winform中传参成功呢?

关于Api中POST,导致405报错

这是客户端调用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啊.....不理解哪个环节出了问题

HttpWebResponse ResponseUri 跳转的URL中存在中文就乱码

C# 代码 string MyLink = “http://www.zei8.net/plus/download.php?open=2&id=55507&uhash=dc74d5c3ccbb8856f2e13515”; HttpWebRequest “request = (HttpWebRequest)WebRequest.Create(MyLink); rettpWebRequest)WebRequest.Create(MyLink);quest.Method = "GET"; request.Headers.Clear(); request.ContentType = "application/x-www-form-urlencoded"; request.KeepAlive = true; request.AllowAutoRedirect = true; HttpWebResponse httpResponse = (HttpWebResponse)request.GetResponse(); string mydownurl = httpResponse.ResponseUri.ToString(); httpResponse.Close(); 服务器端的情况无法控制,我们无法更改服务器端代码。 MyLink 为原始的地址 形式为 http://www.*******.com/plus/download.php?open=2&id=55507&uhash=dc74d5c3ccbb8856f2e13515 我通过以上代码 获取mydownurl得到真实地址,但是当真实地址中存在中文的时候 获取的地址显示为乱码 是这样的地址 http:///www.*******.com/2015/201502/Äê14-20ÈÕ½ðÈÚ°²È«ÔËÐп¼ºËÇé¿öͨ±¨.rar 实际地址是 http:///www.*******.com/2015/201502/《原来康熙》全集.rar 找了个测试地址 http://www.zei8.net/plus/download.php?open=2&id=55507&uhash=dc74d5c3ccbb8856f2e13515

java web项目接收http客户端的post数据

一个无界面的web应用,其接收http客户端post的数据 这方面不是很明白有什么参考资料吗。

c#使用 HttpWebRequest 向服务器post请求,接收返回数据不完整

C# 4.0 ,使用HttpWebRequest向服务器发送post请求,使用HttpWebResponse 接收服务器返回的数据,返回数据有3M左右,但是实际上string只接收到2.2M,数据没有完全接收就结束了。导致接收到的数据不完整无法进行解析。 抓取数据包请求数据包看到数据包内最下方提示:Stream output truncated,求解决

.NET 3.5 发送POST请求 没反应?

旧项目是运行在3.5环境下 现在业务需要发送post 请求 ,但是代码调试运行到 if (method.ToLower() == "post") { HttpWebRequest req = null; HttpWebResponse rsp = null; System.IO.Stream reqStream = null; try { req = (HttpWebRequest)WebRequest.Create(url); req.Method = method; req.KeepAlive = false; req.ProtocolVersion = HttpVersion.Version10; req.Timeout = 5000; req.ContentType = "application/x-www-form-urlencoded;charset=utf-8"; byte[] postData = Encoding.UTF8.GetBytes(BuildQuery(parameters, "dd")); //byte[] postData = System.Text.Encoding.Default.GetBytes( BuildQuery(parameters, "dd")); reqStream = req.GetRequestStream(); reqStream.Write(postData, 0, postData.Length); rsp = (HttpWebResponse)req.GetResponse(); Encoding encoding = Encoding.GetEncoding(rsp.CharacterSet); return GetResponseAsString(rsp, encoding); } catch (Exception ex) { return ex.Message; } finally { if (reqStream != null) reqStream.Close(); if (rsp != null) rsp.Close(); } } rsp = (HttpWebResponse)req.GetResponse();到这就没反应了也不报错。 在在4.5环境下测试没问题。

在C#中 用post用json传递参数 怎么传

在C#中 用post用json传递参数 怎么传,在后台的方法中要把json的参数传递出去,用post怎么传出去啊

c# 用winform程序实现HTTP中post请求

现在在做一个需求,要求用HTTP post方式调用接口实现数据上传,需求内容如下:协议:http方式:POST POST字符串参数为code={0}&keys={1}&writedoc={2} {0},{1},{2}分别对应参数code,keys,writedoc的值。 代码如下: string PostData = string.Format("code={0}&keys={1}&writedoc={2}", "10001", "d587fc05fe8c47b7", xmldoc); Uri url = new Uri(surl); WebRequest myHttpWebRequest = WebRequest.Create(url); myHttpWebRequest.Method = "POST"; myHttpWebRequest.Timeout = 3000; UTF8Encoding encoding = new UTF8Encoding(); byte[] byte1 = encoding.GetBytes(PostData); //myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"; myHttpWebRequest.ContentLength = byte1.Length; //发送成功后接收返回的XML信息 using (Stream newStream = myHttpWebRequest.GetRequestStream()) { newStream.Write(byte1, 0, byte1.Length); HttpWebResponse response = (HttpWebResponse)myHttpWebRequest.GetResponse(); string lcHtml = string.Empty; Encoding enc = Encoding.GetEncoding("UTF-8"); using(Stream stream = response.GetResponseStream()) { StreamReader streamReader = new StreamReader(stream, enc); lcHtml = streamReader.ReadToEnd(); return lcHtml; } } 可是在响应完成之后,服务器那边接收不到我窜过去的参数,各位大神看看我哪里写的不对

太大的GET / POST 503错误

<div class="post-text" itemprop="text"> <p><strong>The problem was solved without changing anything, I think the host was f*cking some things up</strong></p> <p>Im building a website with a few background requests, which use GET and POST statements, but that doesn't matter(for testing it I use GET). When I request the page <a href="http://beta.svshizzle.com/check.php?email=a@b.c&amp;ww=1423304826" rel="nofollow">http://beta.svshizzle.com/check.php?email=a@b.c&amp;ww=1423304826</a>, it only shows me a 503 error page, which is not in my .htmlentities, so the standard one. If I request the same page without any GET values I get a normal response and also with ?email=A@B&amp;.... I get a normal response, so I think that the problem is in the @ and the .(dot/period).</p> <p>My php code(simplified):</p> <pre><code>&lt;?php echo "no error"; ?&gt; </code></pre> <p>Does anyone know the cause of this?</p> <p>PS: Normal pages without GET values with an @ and a . do work as supposed, so I think it is not the server that is unavailable.</p> <p><strong>Update</strong></p> <p>LOG(Apache I thinks, not the php one):</p> <pre><code>beta.svshizzle.com anon-66-249-92-186.ip.invalid - - [27/Jan/2016:17:13:58 +0100] "GET /signup/wwforgot.php?x=arendsurvey@gmail.com&amp;h=868 HTTP/1.1" 503 323 "-" "Mediapartners-Google" beta.svshizzle.com anon-66-249-93-123.ip.invalid - - [27/Jan/2016:17:14:31 +0100] "GET /signup/wwforgot.php?x=arendsurvey@gmail.com&amp;h=868 HTTP/1.1" 503 323 "-" "Mediapartners-Google" beta.svshizzle.com anon-66-249-92-51.ip.invalid - - [27/Jan/2016:17:14:59 +0100] "GET /signup/wwforgot.php?x=arendsurvey@gmail.com&amp;h=868 HTTP/1.1" 503 323 "-" "Mediapartners-Google" beta.svshizzle.com anon-66-249-92-193.ip.invalid - - [27/Jan/2016:17:15:31 +0100] "GET /signup/wwforgot.php?x=arendsurvey@gmail.com&amp;h=868 HTTP/1.1" 503 323 "-" "Mediapartners-Google" beta.svshizzle.com anon-66-249-92-151.ip.invalid - - [27/Jan/2016:17:15:59 +0100] "GET /signup/wwforgot.php?x=arendsurvey@gmail.com&amp;h=868 HTTP/1.1" 503 323 "-" "Mediapartners-Google" beta.svshizzle.com anon-66-249-93-0.ip.invalid - - [27/Jan/2016:17:16:33 +0100] "GET /signup/wwforgot.php?x=arendsurvey@gmail.com&amp;h=868 HTTP/1.1" 503 323 "-" "Mediapartners-Google" beta.svshizzle.com anon-82-170-27-149.ip.invalid - - [27/Jan/2016:17:16:43 +0100] "GET /signup/wwforgot.php?x=arendsurvey@gmail.com&amp;h=868 HTTP/1.1" 503 323 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36" beta.svshizzle.com anon-82-170-27-149.ip.invalid - - [27/Jan/2016:17:16:48 +0100] "GET /signup/wwforgot.php?x=arendsurvey@gmail.com&amp;h=868 HTTP/1.1" 503 323 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36" beta.svshizzle.com anon-82-170-27-149.ip.invalid - - [27/Jan/2016:17:19:04 +0100] "POST /check.php HTTP/1.1" 503 323 "http://beta.svshizzle.com/signin.php" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36" </code></pre> <p>This was the exact code I was using for debugging this problem, with only that piece of code it crashed, I don't know if it happens with no code.</p> <p>I think urlencode doesn't work, because the php script doesn't even get started.</p> </div>

c# jsonpost 数组 不成功

本人要post json 数据,数据里出现数组memberList时post返回"Unknown property 'memberList'"错误 ,去掉memberList数组post成功,不明白?? string temp2 = "{\"memberList\":[{\"userId\":\"\",\"userName\":\"吴\",\"userPhone\":\"1382562699\"}],\"distCode\":\"44120100003\",\"beginTime\":\"2015-10-10 08:00:00\",\"script\":\"12语音\",\"endTime\":\"2015-10-10 18:00:00\",\"activityName\":\"任务名称\"}"; string strUrl = @"http://10.150.29.234:9080/ocmx2/activity/taskDetail.action"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strUrl); request.Method = "POST"; request.ContentType = "application/json;charset=GBK"; byte[] payload=System.Text.Encoding.GetEncoding("GBK").GetBytes(temp2); //将Json字符串转化为字节 //设置请求的ContentLength request.ContentLength =payload.Length; //发送请求,获得请求流 System.IO.Stream writer; try { writer = request.GetRequestStream();//获取用于写入请求数据的Stream对象 } catch (Exception) { writer = null; } //将请求参数写入流 writer.Write(payload, 0, payload.Length); writer.Close();//关闭请求流 // String strValue = "";//strValue为http响应所返回的字符流 HttpWebResponse response=null; try { //获得响应流 response = (HttpWebResponse)request.GetResponse(); } catch (WebException ex) { // response = ex.Response; } string StrDate = ""; string strValue = ""; System.IO.Stream s =response.GetResponseStream(); System.IO.StreamReader Reader = new System.IO.StreamReader(s, Encoding.GetEncoding("GBK")); while ((StrDate = Reader.ReadLine()) != null) { strValue += StrDate + "\r\n"; } textBox2.Text = strValue; s.Close();

WCF 如何通过POST 接收和返回参数为空

WCF作为服务端,目前是寄宿在IIS,客户端是普通的winform,就想简单的做一个“发送请求”、“返回结果”的功能。 但是服务端显示参数一直是null。 用的json格式。 WCF接口代码: [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "GetConnection", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] ResultInfo GetConnection(KeyValuePair<string,object> data); 接口实现: public ResultInfo GetConnection(KeyValuePair<string, object> data) { //这里监视到的data就是null return new ResultInfo(){IsSuccessed = true,}; //返回值是自己定义的一个类 } 客户端调用: public static string SendHttpRequest(string requestURI, string requestMethod, string json,int timeOut = 300000) { //json格式请求数据 string requestData = json; //拼接URL string serviceUrl = string.Format("{0}/{1}", requestURI, requestMethod); HttpWebRequest myRequest = null; myRequest = (HttpWebRequest)WebRequest.Create(serviceUrl); //utf-8编码 byte[] buf = Encoding.GetEncoding("UTF-8").GetBytes(requestData); //post请求 myRequest.Method = "POST"; myRequest.ContentLength = buf.Length; myRequest.ContentType = "application/json"; myRequest.MaximumAutomaticRedirections = 1; myRequest.AllowAutoRedirect = true; myRequest.Timeout = timeOut; Stream newStream = myRequest.GetRequestStream(); newStream.Write(buf, 0, buf.Length); newStream.Close(); HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8); string ReqResult = reader.ReadToEnd(); reader.Close(); myResponse.Close(); return ReqResult; } 传入的json在客户端看是正常的: Key是Guid,Value是一个自己定义的类型 {"Key":"6aafd4a3-6d9d-4bab-adb6-f5fe718437c1","Value":{"ComputerName":"Desk-Top","IpAddress":"192.169.6.126","Mac":null}} 也查了不少资料,可能悟性有限,一直没能解决,头大。 试过加上数据契约 比如 [DataContract] public class PcInfo { [DataMember] public string ComputerName{set;get;}....... } 服务端接受的一直是null。 求大牛不吝赐教。。小弟感激不尽

c# winfrom post请求网址带多个参数的问题 请看下面代码

``` string strURL = "http://www.cqjg.gov.cn/newwww/c7/clwz.asp"; System.Net.HttpWebRequest request; request = (System.Net.HttpWebRequest)WebRequest.Create(strURL); //Post请求方式 request.Method = "POST"; //内容类型 request.ContentType = "application/x-www-form-urlencoded"; //参数经过URL编码 string paraUrlCoded = System.Web.HttpUtility.UrlEncode("Name"); paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode(txtCarId .Text.Trim()); paraUrlCoded +="& "+ System.Web.HttpUtility.UrlEncode("Age"); paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode(txtCarNumber.Text.Trim()); byte[] payload; //将URL编码后的字符串转化为字节 payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded); //设置请求的ContentLength request.ContentLength = payload.Length; //获得请求流 Stream writer = request.GetRequestStream(); //将请求参数写入流 writer.Write(payload, 0, payload.Length); //关闭请求流 writer.Close(); System.Net.HttpWebResponse response; //获得响应流 response = (System.Net.HttpWebResponse)request.GetResponse(); System.IO.Stream s; s = response.GetResponseStream(); string StrDate = ""; string strValue = ""; StreamReader Reader = new StreamReader(s,Encoding.Default); while ((StrDate= Reader.ReadLine())!=null) { strValue += StrDate+"\r\n"; } // txtInfo.Text = strValue; txtInfo.Text= FindContent(strValue); ``` 如果浏览器请求的 正文是 Name=小明那么 string paraUrlCoded = System.Web.HttpUtility.UrlEncode("Name"); paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode(txtCarId .Text.Trim()); 就能成功 如果是Name=小明&type=1 string paraUrlCoded = System.Web.HttpUtility.UrlEncode("Name"); paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode(txtCarId .Text.Trim()); paraUrlCoded +="& "+ System.Web.HttpUtility.UrlEncode("type"); paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode(1); 这样就会失败提交不成功 还有问下如果请求主题是{"Item":{"Name":"小明"}}这样子或者是{"Name":"test"}这样子的话我该怎么传呢? 麻烦请教下了

C#https的post请求,发送的uri接收方接收的地址乱了

public string HttpPost(string Url, string postDataStr) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); //request.AllowAutoRedirect = false; //禁止自动重定向 request.Method = "POST"; request.Headers.Add("AK", "c74f6e81f3854e928a4e2633b9d55a89"); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = Encoding.UTF8.GetByteCount(Url); request.CookieContainer = cookie; //cookie信息由CookieContainer自行维护 Stream myRequestStream = request.GetRequestStream(); using (StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312")))//gb2312 { myStreamWriter.Write(Url); myStreamWriter.Close(); } HttpWebResponse response = null; try { this.SetCertificatePolicy(); response = (HttpWebResponse)request.GetResponse(); } catch (System.Exception ex) { throw; } //获取重定向地址 //string url1 = response.Headers["Location"]; if (response != null) { Stream myResponseStream = response.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8")); string retString = myStreamReader.ReadToEnd(); //MessageBox.Show(retString); myStreamReader.Close(); myResponseStream.Close(); return retString; } else { return "error"; //post请求返回为空 } } ``` 我发的:https://console-api-test.qibeitech.com/sign/productCheck/bindDevice?lockId=86812017491050&bikeId=http://ofo.so/plate/11000000&timestamp=1504487889209&sign=3c02b0dd1c2b5ba9df236b78e89c5916 他们接收的:AKc74f6e81f3854e928a4e2633b9d55a89bikeIdhttp://ofo.so/plate/11000000http://ofo.so/plate/11000000https://console-api-test.qibeitech.com/sign/productCheck/bindDevice?lockId86812017491050lockId86812017491050timestamp15044878892091504487889209dcc59608864511e79673163ea306a3 ``` 求帮助,小白一个,,之前没怎么做过网络通信的

c# winform向一般处理程序(ashx) Post数据的时候 对特殊字符编码的问题

winfrom POST代码 url=http://192.168.1.101:8089/Handle/B.ashx pdata="a=ert45/sd2=&babc=/&c=123=/" ``` public static string PostHttpHandle(string url, string pdata) { Dictionary<string, string> dd = new Dictionary<string, string>(); dd.Add(url, pdata); string udata = string.Empty; foreach (KeyValuePair<string, string> kvp in dd) { System.Net.HttpWebRequest request2; request2 = (System.Net.HttpWebRequest)WebRequest.Create(kvp.Key); request2.Method = "POST"; request2.ContentType = "application/x-www-form-urlencoded;"; byte[] payload; payload = System.Text.Encoding.UTF8.GetBytes(kvp.Value); request2.ContentLength = payload.Length; Stream writer = request2.GetRequestStream(); writer.Write(payload, 0, payload.Length); writer.Close(); System.Net.HttpWebResponse response; response = (System.Net.HttpWebResponse)request2.GetResponse(); System.IO.Stream s; s = response.GetResponseStream(); StreamReader reader = new StreamReader(s); udata = reader.ReadToEnd(); reader.Close(); } return HttpUtility.UrlEncode(udata, System.Text.Encoding.UTF8); } ``` ashx 接收的代码 ## //输出会把=号变成%3D /变成%3f ``` public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string token = string.Format(HttpUtility.UrlDecode( context.Request.Form["a"]),System.Text.Encoding.UTF8); string jqm = string.Format(HttpUtility.UrlDecode( context.Request.Form["b"]),System.Text.Encoding.UTF8); string my = string.Format(HttpUtility.UrlDecode( context.Request.Form["c"]),System.Text.Encoding.UTF8); context.Response.Write(my) } ``` 我想我发送过去的= 和 / 符号 服务器端接收就是=号和/符号 不要编码 另外服务端返回的 = 和 / 符号 我能也能接收到 向服务器POST加密的数据就一定会用到=和/ 这些特殊符号

验证Curl HTTP Post

<div class="post-text" itemprop="text"> <p>Hi I am trying to send POST request through CURL but its throwing an error which says<br> "Failed connect to qaservices.carrental.com:443; No error".</p> <p>The username and password is already included in the soap header in an xml file</p> <pre><code>&lt;?php $filename = 'c:/v.xml'; $data = file_get_contents($filename); $url = 'https://qaservices.carrental.com/wsbang/HTTPSOAPRouter/ws9071'; $soap_do = curl_init(); curl_setopt($soap_do, CURLOPT_URL, $url ); curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($soap_do, CURLOPT_TIMEOUT, 10); curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true ); curl_setopt($soap_do, CURLOPT_POST, true ); curl_setopt($soap_do, CURLOPT_HEADER, 0 ); curl_setopt($soap_do, CURLOPT_POSTFIELDS, $data); $result = curl_exec($soap_do); $err = curl_error($soap_do); if ( curl_errno($soap_do) ) { $result = 'ERROR -&gt; ' . curl_errno($soap_do) . ': ' . curl_error($soap_do); } else { $returnCode = (int)curl_getinfo($soap_do, CURLINFO_HTTP_CODE); switch($returnCode) { case 200: break; default: $result = 'HTTP ERROR -&gt; ' . $returnCode; break; } } curl_close($ch); echo $result; ?&gt; </code></pre> <p>When i try to send HttpWebRequest in vb.net this works. the copy of code in vb.net is </p> <pre><code> doc.Load("c:/v.xml") Dim content As String = doc.InnerXml Dim urlEncoded As String = content Dim encodedRequest As Byte() = New ASCIIEncoding().GetBytes(urlEncoded) Dim request As HttpWebRequest = DirectCast(WebRequest.Create("https://qaservices.carrental.com/wsbang/HTTPSOAPRouter/ws9071"), HttpWebRequest) request.Method = "POST" request.Accept = "*/*" request.ContentType = "application/x-www-form-urlencoded" ' request.UserAgent = "Custom REST client v1.0" request.ContentLength = encodedRequest.Length request.Proxy.Credentials = CredentialCache.DefaultCredentials Dim reqStream As Stream = request.GetRequestStream() reqStream.Write(encodedRequest, 0, encodedRequest.Length) reqStream.Flush() reqStream.Close() Dim response As HttpWebResponse = (request.GetResponse()) Dim responseStream As Stream = response.GetResponseStream() Dim streamReader As New StreamReader(responseStream) Dim responseContent As String = streamReader.ReadToEnd </code></pre> <p>I think it has to do something in setting up proxy credential Can anyone please guide me in correct path</p> </div>

2019 Python开发者日-培训

2019 Python开发者日-培训

150讲轻松搞定Python网络爬虫

150讲轻松搞定Python网络爬虫

设计模式(JAVA语言实现)--20种设计模式附带源码

设计模式(JAVA语言实现)--20种设计模式附带源码

YOLOv3目标检测实战:训练自己的数据集

YOLOv3目标检测实战:训练自己的数据集

java后台+微信小程序 实现完整的点餐系统

java后台+微信小程序 实现完整的点餐系统

三个项目玩转深度学习(附1G源码)

三个项目玩转深度学习(附1G源码)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

2019 AI开发者大会

2019 AI开发者大会

玩转Linux:常用命令实例指南

玩转Linux:常用命令实例指南

一学即懂的计算机视觉(第一季)

一学即懂的计算机视觉(第一季)

4小时玩转微信小程序——基础入门与微信支付实战

4小时玩转微信小程序——基础入门与微信支付实战

Git 实用技巧

Git 实用技巧

Python数据清洗实战入门

Python数据清洗实战入门

使用TensorFlow+keras快速构建图像分类模型

使用TensorFlow+keras快速构建图像分类模型

实用主义学Python(小白也容易上手的Python实用案例)

实用主义学Python(小白也容易上手的Python实用案例)

程序员的算法通关课:知己知彼(第一季)

程序员的算法通关课:知己知彼(第一季)

MySQL数据库从入门到实战应用

MySQL数据库从入门到实战应用

机器学习初学者必会的案例精讲

机器学习初学者必会的案例精讲

手把手实现Java图书管理系统(附源码)

手把手实现Java图书管理系统(附源码)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

.net core快速开发框架

.net core快速开发框架

玩转Python-Python3基础入门

玩转Python-Python3基础入门

Python数据挖掘简易入门

Python数据挖掘简易入门

微信公众平台开发入门

微信公众平台开发入门

程序员的兼职技能课

程序员的兼职技能课

Windows版YOLOv4目标检测实战:训练自己的数据集

Windows版YOLOv4目标检测实战:训练自己的数据集

HoloLens2开发入门教程

HoloLens2开发入门教程

微信小程序开发实战

微信小程序开发实战

Java8零基础入门视频教程

Java8零基础入门视频教程

相关热词 c# 开发接口 c# 中方法上面的限制 c# java 时间戳 c#单元测试入门 c# 数组转化成文本 c#实体类主外键关系设置 c# 子函数 局部 c#窗口位置设置 c# list 查询 c# 事件 执行顺序
立即提问
相关内容推荐