1
void SendPost()
            {
                var url = "http://{ipaddress}/Network/Records/Registration?fname=tt&lname=tt&username=dddddddd&password=tt";

                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
                myRequest.Method = "POST";
                myRequest.ContentType = "application/x-www-form-urlencoded";

                myRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), myRequest);
    }
void GetRequestStreamCallback(IAsyncResult asynchronousResult)
        {
            HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
            System.IO.Stream postStream = request.EndGetRequestStream(asynchronousResult);
            string parametersString = "";


            byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(str);
            // Write to the request stream.
            postStream.Write(byteArray, 0, byteArray.Length);
            postStream.Close();
            // Start the asynchronous operation to get the response
            request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
}



 void GetResponseCallback(IAsyncResult asynchronousResult)
        {

                HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
                HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
                Stream streamResponse = response.GetResponseStream();
                StreamReader streamRead = new StreamReader(streamResponse);
                string responseString = streamRead.ReadToEnd();
                // Close the stream object
                streamResponse.Close();
                streamRead.Close();
                // Release the HttpWebResponse
                response.Close();
}

我编写了上面的代码以将图像作为字节发送。它没有给出任何错误。但是图像没有正确上传。我在下面的代码中传递 base64 图像字符串。

byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(str);

请告诉我出了什么问题。为什么图片无法正确上传?

4

1 回答 1

0

请参阅:带参数的照片上传到 PHP 页面

这: http: //nediml.wordpress.com/2012/05/10/uploading-files-to-remote-server-with-multiple-parameters/

于 2012-05-25T06:13:24.047 回答