public String SendPost(String postName[],String postValue[]) throws Exception
{
URL PostUrl = new URL(strUrl);
HttpURLConnection connection = (HttpURLConnection)PostUrl.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
PrintWriter outData = new PrintWriter(connection.getOutputStream());
//encode the message
String strPostData="",strPostName="";
for(int i=0;i<postName.length;i++)
{
strPostName = postName[i];
strPostData += postName[i] + "=" + URLEncoder.encode(postValue[i],"UTF-8") + "&";
}
//send the encoded message
outData.println(strPostData);
outData.close(); return strPostData;
}
调用这个函数时,如果把postValue[i]直接写成字符串,如"测试",接收的url就正确,但是通过postValue[i]就不行了
{
URL PostUrl = new URL(strUrl);
HttpURLConnection connection = (HttpURLConnection)PostUrl.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
PrintWriter outData = new PrintWriter(connection.getOutputStream());
//encode the message
String strPostData="",strPostName="";
for(int i=0;i<postName.length;i++)
{
strPostName = postName[i];
strPostData += postName[i] + "=" + URLEncoder.encode(postValue[i],"UTF-8") + "&";
}
//send the encoded message
outData.println(strPostData);
outData.close(); return strPostData;
}
调用这个函数时,如果把postValue[i]直接写成字符串,如"测试",接收的url就正确,但是通过postValue[i]就不行了
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货