java+post+php

package com.hrtec;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import org.json.JSONObject;
import org.omg.CORBA.portable.InputStream;

public class Demo {
	
	public static void main(String[] args) throws UnsupportedEncodingException, IOException {
		
		URL url=new URL("http://localhost:15769/a.php");
		URLConnection c=url.openConnection();
		
		c.setDoOutput(true);
		c.setDoInput(true);
		
		OutputStreamWriter out=new OutputStreamWriter(c.getOutputStream(), "UTF-8");
		out.write("name=123&pw=110");
		out.flush();
		BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(c.getInputStream()));
		String line="";
		StringBuilder sb=new StringBuilder();
		while (null!=(line=bufferedReader.readLine())){
				sb.append(line);
			}
		String result= sb.toString();
		System.out.println(result);
	}

}

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页