生活随笔
收集整理的這篇文章主要介紹了
【javascript】ajax跨域post传值
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
jsp跨域訪問代理,雖然實現了,但是我這里post方式傳值二進制值過大無法實現。悲劇還是沒達到理想效果。
<%@ page import="java.net.*,java.util.*,java.lang.*,java.io.*,java.net.URLEncoder"%>
<%@ page contentType="text/xml;charset=gb2312"%>
<%String url = null;StringBuffer params = new StringBuffer();Enumeration enu = request.getParameterNames();int total = 0;while (enu.hasMoreElements()) {String paramName = (String) enu.nextElement();if (paramName.equals("url")) {url = request.getParameter(paramName);} else {if (total == 0) {params.append(paramName).append("=").append(URLEncoder.encode(request.getParameter(paramName), "UTF-8"));} else {params.append("&").append(paramName).append("=").append(URLEncoder.encode(request.getParameter(paramName),"UTF-8"));}++total;}}String para = request.getParameter("file");//System.out.println("=========="+url.toString()+"?file="+URLEncoder.encode(para));System.out.println("=========="+URLEncoder.encode(para).substring(0,500));if (url != null) {// 使用GET方式向目的服務器發送請求URL connect = new URL(url.toString()+"?file="+URLEncoder.encode(para).toString()+"&fileName=sss");URLConnection connection = connect.openConnection();HttpURLConnection httpConn = (HttpURLConnection) connection;//connection.setDoOutput(true);//connection.setDoInput(true);//connection.setRequestProperty("Content-type",// "application/x-www-form-urlencoded");//connection.connect();// httpConn.setRequestProperty("Content-Length", String.valueOf(b.length));// httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");//httpConn.setRequestProperty("SOAPAction", SOAPAction);httpConn.setRequestMethod("POST");httpConn.setDoOutput(true);httpConn.setDoInput(true);httpConn.setRequestProperty("Content-type","application/x-www-form-urlencoded");httpConn.connect();//獲得連接輸出流 DataOutputStream os = new DataOutputStream(connection.getOutputStream());os.flush();os.close();BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));String line;while ((line = reader.readLine()) != null) {out.println(line);}reader.close();}
%>
總結
以上是生活随笔為你收集整理的【javascript】ajax跨域post传值的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。