當前位置:編程學習大全網 - 網站源碼 - java中,如何用POST方法將參數傳遞給第三方網站

java中,如何用POST方法將參數傳遞給第三方網站

使用org.apache.commons.";

static final int LOGON_PORT = 80;

public FormLoginDemo() {

super();

}

public static void main(String[] args) throws Exception {

HttpClient client = new HttpClient();

client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");

PostMethod authpost = new PostMethod("/servlet/SessionServlet");

// 準備登錄參數

NameValuePair action = new NameValuePair("action", "login");

NameValuePair url = new NameValuePair("url", "/index.html");

NameValuePair userid = new NameValuePair("UserId", "userid");

NameValuePair password = new NameValuePair("Password", "password");

authpost.setRequestBody(

new NameValuePair[] {action, url, userid, password});

// 執行Post請求

client.executeMethod(authpost);

// 打印狀態碼

System.out.println("Login form post: " + authpost.getStatusLine().toString());

// 釋放連接

authpost.releaseConnection();

}

}

  • 上一篇:有哪些海外雲手機?
  • 下一篇:webupload如何實現多個按鈕共享壹個上傳隊列?
  • copyright 2024編程學習大全網