主要涉及到中文的位置:
- String body = "謝彬測(cè)試微信支付0.01_2";
- String detail = "謝彬0.01_元測(cè)試開始";
- String attach = "備用參數(shù),先留著,后面會(huì)有用的";
不光有中文還有下劃線,在“統(tǒng)一下單”的時(shí)候,一直提示:body不是utf8編碼
網(wǎng)上各種iso8859-1的轉(zhuǎn)換說(shuō)明,我只想說(shuō),每個(gè)人的代碼都不一樣,不能拿來(lái)直接用!?。。?/p>
我的貌似是另外一個(gè)地方編碼出了問(wèn)題 http://bbs.csdn.net/topics/391022204,以下是關(guān)鍵部分代碼:
- /**
- * post請(qǐng)求并得到返回結(jié)果
- * @param requestUrl
- * @param requestMethod
- * @param output
- * @return
- */
- public static String httpsRequest(String requestUrl, String requestMethod, String output) {
- try{
- URL url = new URL(requestUrl);
- HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
- connection.setDoOutput(true);
- connection.setDoInput(true);
- connection.setUseCaches(false);
- connection.setRequestMethod(requestMethod);
- if (null != output) {
- OutputStream outputStream = connection.getOutputStream();
- outputStream.write(output.getBytes("UTF-8"));
- outputStream.close();
- }
- // 從輸入流讀取返回內(nèi)容
- InputStream inputStream = connection.getInputStream();
- InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
- BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
- String str = null;
- StringBuffer buffer = new StringBuffer();
- while ((str = bufferedReader.readLine()) != null) {
- buffer.append(str);
- }
- bufferedReader.close();
- inputStreamReader.close();
- inputStream.close();
- inputStream = null;
- connection.disconnect();
- return buffer.toString();
- }catch(Exception ex){
- ex.printStackTrace();
- }
-
- return "";
- }
調(diào)用:
- //構(gòu)造xml參數(shù)
- String xmlInfo = HttpXmlUtils.xmlInfo(unifiedorder);
-
- System.out.println(xmlInfo);
-
- String wxUrl = UnifiedorderUrl;
-
- String method = "POST";
-
- String weixinPost = HttpXmlUtils.httpsRequest(wxUrl, method, xmlInfo).toString();
-
- System.out.println(weixinPost);
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。