How to send bytes image to service in windows phone 7?

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();
}

I wrote above code for sending image as bytes.it's not giving any errors.but image was not uploading properly. i am passing base64 string of image in below code.

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

Please tell me what was wrong.why image was not uploading properly?

Answers


See this: Photo upload with parameters to a PHP page

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


Need Your Help

SQL 2008 Reporting Services "HTTP Error 503. The service is unavailable."

ssrs-2008 windows-server-2008-r2

SQl 2008 Reporting Services (SP1, CU4) installed on Windows 2008 R2. Service account is configured to use Network Service. Port 80 is open in the Firewall. Continue to get "HTTP Error 503. The serv...

Javascript Validation - Letters and Space

javascript regex validation

Good day. I'm very new to Javascript. I have this expression: var firstname = /^[A-Za-z]+$/; to validate first name in a form. However, this code only allows the user to input a single name without...