POST Requests on WP7

前端 未结 5 2125
傲寒
傲寒 2021-02-11 05:20

I\'ve been dying for about 6 hours trying to figure out how to make a regular POST request in WP7 , I tried the answers of similar questions posted here and on many other places

5条回答
  •  余生分开走
    2021-02-11 05:56

    To add post data just call BeginGetRequestStream method (also, BeginGetResponse move to GetRequestStreamCallback)

    request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request);
    
    void GetRequestStreamCallback(IAsyncResult asynchronousResult)
    {
        HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
        // End the stream request operation
        Stream postStream = webRequest.EndGetRequestStream(asynchronousResult);
    
        // Create the post data
        string postData = "post data";
        byte[] byteArray = Encoding.Unicode.GetBytes(postData);
    
        // Add the post data to the web request            
        postStream.Write(byteArray, 0, byteArray.Length);
        postStream.Close();
    
        // Start the web request
        webRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), webRequest);
    }
    

提交回复
热议问题