LUA XMLHttpRequest post 怎么传参数进去

2025-03-11 04:36:03
推荐回答(1个)
回答1:

JAVA HttpURLConnection Post方式提交传递参数 的示例如下:

package wzq.j2se;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class HttpURLConnectionPost {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
readContentFromPost();
}
public static void readContentFromPost() throws IOException {
// Post请求的url,与get不同的是不需要带参数
URL postUrl = new URL("http://www.wangzhiqiang87.cn");
// 打开连接
HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection();

// 设置是否向connection输出,因为这个是post请求,参数要放在
// http正文内,因此需要设为true
connection.setDoOutput(true);
// Read from the connection. Default is true.
connection.setDoInput(true);
// 默认是 GET方式
connection.setRequestMethod("POST");

// Post 请求不能使用缓存
connection.setUseCaches(false);

connection.setInstanceFollowRedirects(true);