windows phone 7 - Post ampersand character to HttpWebRequest -
i need pass string server contains 1 or few value. api grammar following:
&track=name or &track=name&artist=name
however server return blank string. if remove char &, server return thing this: "�\b\0\0\0\0\0\0\0�zi��f��ϯ��
string post = "track=love"; // post = post.replace("&", "%26"); // httputility.urlencode(post);
what should do? should have & char included or need read result server? code follow:
protected override void onnavigatedto(system.windows.navigation.navigationeventargs e) { s = navigationcontext.querystring["parameter1"]; // string strconnecturl = "http://mp3.rolo.vn/mp3/search"; try { httpwebrequest webrequest = (httpwebrequest)webrequest.create(strconnecturl); webrequest.method = "post"; webrequest.contenttype = "application/x-www-form-urlencoded;charset=utf-8"; // start asynchronous operation webrequest.begingetrequeststream(new asynccallback(getrequeststreamcallback), webrequest); } catch (exception ex) { messagebox.show(ex.tostring()); } } private static void getrequeststreamcallback(iasyncresult asynchronousresult) { string post = "track=love"; try { httpwebrequest request = (httpwebrequest)asynchronousresult.asyncstate; // end operation stream poststream = request.endgetrequeststream(asynchronousresult); // convert string byte array. byte[] postbytes = encoding.utf8.getbytes(post); // write request stream. poststream.write(postbytes, 0, postbytes.length); poststream.close(); // start asynchronous operation response request.begingetresponse(new asynccallback(getresponsecallback), request); } catch (exception ex) { messagebox.show(ex.tostring()); } } // static stream str; static string st; private static void getresponsecallback(iasyncresult asynchronousresult) { httpwebrequest request = (httpwebrequest)asynchronousresult.asyncstate; // end operation httpwebresponse response = (httpwebresponse)request.endgetresponse(asynchronousresult); httpstatuscode rcode = response.statuscode; stream streamresponse = response.getresponsestream(); streamreader streamread = new streamreader(streamresponse); //this return "" value, expect return xml string st = streamread.readtoend(); //console.writeline(responsestring); // close stream object streamresponse.close(); streamread.close(); // release httpwebresponse response.close(); }
it's form post, use ampersand separate key values: track=name&artist=name
" "�\b\0\0\0\0\0\0\0�zi��f��ϯ��" -> looks result compressed.
Comments
Post a Comment