C # Post data Base64 to interface error issues

Source: Internet
Author: User


This base64 in Requestheader.
base64=hysgng22yx0aijnqvnjw0xhebi32nh%2birvkdkbomuikpxw0% 2fs6rugflmsa527y8zz3gmezfxmb8ry8fh5gjgejfgqfxdc4a2hllvifzyideucqlogdajoola8jnif1c8nwrte0gncrm5rxkshlkzp2itzclgdcyz6ogaf7o Lnluob44cz3agf1q8hvgme8leqgoqxsiztt3xn%2b96j7zp%2fwa%3d

He turned the base64 into something like%2f.

So the webservice received the parameter is wrong.


Workaround:

stringBase64 ="base64=hysgng22yx0aijnqvnjw0xhebi32nh+irvkdkbomuikpxw0/ S6rugflmsa527y8zz3gmezfxmb8ry8fh5gjgejfgqfxdc4a2hllvifzyideucqlogdajoola8jnif1c8nwrte0gncrm5rxkshlkzp2itzclgdcyz6ogaf7oln Luob44cz3agf1q8hvgme8leqgoqxsiztt3xn+96j7zp/wa=";byte[] buffer =convert.frombase64string (base64);stringBase64strdata = convert.tobase64string (buffer). Replace ("+","%2b");//Note that the plus (' + ') substitution is handled, otherwise the BASE64 string is not valid because the plus sign passes through the URL and becomes a space        stringPostData ="str="+Base64strdata; byte[] DataArray = Encoding.Default.GetBytes (postdata);

/// <summary>        ///POST request and get results/// </summary>         Public Static stringHttpPost (stringUrlstringpostdatastr) {            Try{postdatastr= Postdatastr.replace ("+","%2b"); HttpWebRequest Request=(HttpWebRequest) webrequest.create (URL); Request. Method="POST"; Request. Timeout=6000000; Request. ContentType="application/x-www-form-urlencoded"; Request. ContentLength=postdatastr.length; StreamWriter writer=NewStreamWriter (Request.                GetRequestStream (), encoding.ascii); Writer.                Write (POSTDATASTR); Writer.                Flush (); HttpWebResponse Response=(HttpWebResponse) request.                GetResponse (); stringencoding =Response.                ContentEncoding; if(Encoding = =NULL|| Encoding. Length <1) {Encoding="UTF-8";//default Encoding} StreamReader Reader=NewStreamReader (response.                GetResponseStream (), encoding.getencoding (Encoding)); stringRetString =Reader.                ReadToEnd (); returnretstring; }            Catch(Exception ex) {return NULL; }        }

C # Post data Base64 to interface error issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.