我试图制作一个快速的 Java 应用程序,将数据发布到网站只是基本的 $_POST 变量。可能吗?
谢谢。
例如,它的工作原理是这样的
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
try {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://some.server.com/script.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("var1", "value1"));
nameValuePairs.add(new BasicNameValuePair("var2", "value2"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
InputStream result = response.getEntity().getContent();
} catch (ClientProtocolException e) {
} catch (IOException e) {
}