English 中文(简体)
2. 支付大量的持久性有机污染物数据
原标题:Sending large amounts of POST data
  • 时间:2012-05-13 07:04:42
  •  标签:
  • c#
  • http
  • post

因此,制定方案,由你们提供一些信息。 一部分信息需要一段案文,我们谈论的是100+特性。 我发现的是,数据大到哪里才获得数据。 这里我使用的是:

    public void HttpPost(string URI, string Parameters)
    {
        // this is what we are sending
        string post_data = Parameters;

        // this is where we will send it
        string uri = URI;

        // create a request
        HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri); 
        request.KeepAlive = false;
        request.ProtocolVersion = HttpVersion.Version10;
        request.Method = "POST";

        // turn our request string into a byte stream
        byte[] postBytes = Encoding.ASCII.GetBytes(post_data);

        // this is important - make sure you specify type this way
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = postBytes.Length;
        Stream requestStream = request.GetRequestStream();

        // now send it
        requestStream.Write(postBytes, 0, postBytes.Length);
        requestStream.Close();
    }

当时我这样说:

 HttpPost(url, "data=" + accum + "&pass=HRS");

accum是我寄送的大量数据。 如果我寄送少量数据,这一方法就行之有效。 但是,当它占据巨头时,它就赢得了输电。 我的网站上有超过100+特性的请设员额请求的网页吗?

Thanks.

问题回答

http://www.un.org/Depts/DGACM/index_russian.htm 这并没有使请求得到响应,否则,将传给国际红十字与红新月联会。

您需要打电话<代码>WebRequest。 GetResponse()实际向网络服务器提出请求。

因此,将你的法典结尾改为:

 // Using statement to auto-close, even if there s an exception
 using (Stream requestStream = request.GetRequestStream())
 {
     requestStream.Write(postBytes, 0, postBytes.Length);
 }

 // Now we re ready to send the data, and ask for a response
 using (WebResponse response = request.GetResponse())
 {
     // Do you really not want to do anything with the response?
 }

我用这种方式将JSON数据张贴在请求中......我猜测该数据有点不同,但可以工作。

httpWebRequest = (HttpWebRequest)WebRequest.Create(RequestURL);
httpWebRequest.ContentType = "application/json";
                httpWebRequest.Accept = "application/json";
                httpWebRequest.Method = "POST";
String username = "UserName";
String password = "passw0rd";
String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
httpWebRequest.Headers.Add("Authorization", "Basic " + encoded);
 using (StreamWriter sw = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{" +
                                    ""user":[ "" + user + ""] " +
                                    "}";
                    sw.Write(json);
                    sw.Flush();
                    sw.Close();
                }
using (HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse())
                {


                    //var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                    {
                        var responseText = streamReader.ReadToEnd();
                        //Now you have your response.
                        //or false depending on information in the response
                    }

                    httpResponse.Close();
                }




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签