日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java服务器http post_使用Java程序通过http post访问ABAP Netweaver服务器

發布時間:2025/3/21 java 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java服务器http post_使用Java程序通过http post访问ABAP Netweaver服务器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Created by Jerry Wang, last modified on Aug 20, 2014

source code如下:

import java.io.FileNotFoundException;

import java.io.IOException;

import org.apache.commons.codec.binary.Base64;

import org.apache.http.HttpEntity;

import org.apache.http.HttpResponse;

import org.apache.http.client.ClientProtocolException;

import org.apache.http.client.HttpClient;

import org.apache.http.client.methods.HttpPost;

import org.apache.http.entity.mime.HttpMultipartMode;

import org.apache.http.entity.mime.MultipartEntityBuilder;

import org.apache.http.impl.client.DefaultHttpClient;

import org.apache.http.util.EntityUtils;

@SuppressWarnings("deprecation")

public class MyHTTPPost

{

final private static String POST_PREFIX = ;

private static String getRequestURL(String str)

{

String url = POST_PREFIX + str;

url = url + "&sid=" + Math.random();

return url;

}

private static void sendHTTPPostRequest(String str) throws FileNotFoundException

{

HttpClient httpclient = new DefaultHttpClient();

String raw = "WANGJER:Saptest1";

String encoded = Base64.encodeBase64String(raw.getBytes());

HttpPost httppost = new HttpPost(getRequestURL(str));

MultipartEntityBuilder builder = MultipartEntityBuilder.create();

builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);

builder.addTextBody("firstName", "Jerry");

builder.addTextBody("lastName", "Wang");

try {

httppost.addHeader("Content-Type","multipart/form-data; boundary=assdsfdffafasf");

httppost.addHeader("User-Agent","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");

httppost.addHeader("Authorization", "Basic " + encoded);

HttpResponse httpresponse = httpclient.execute(httppost);

HttpEntity resEntity = httpresponse.getEntity();

String response = EntityUtils.toString(resEntity);

System.out.println(response);

}

catch (IOException e)

{

System.out.println(e.getLocalizedMessage());

e.printStackTrace();

System.out.println("error!");

}

}

public static void main(String[] args) throws ClientProtocolException, IOException

{

sendHTTPPostRequest("a");

}

}

運行結果:

application server會解析出Java program傳入的http 請求中的"a", 然后從DB table scarr 中查找對應的記錄,返回給Java side:

American AirlinesAir CanadaAir FranceAlitaliaBritish AirwaysAir PacificContinental AirlinesDelta AirlinesAir BerlinLufthansaLauda AirJapan AirlinesNorthwest AirlinesQantas AirwaysSouth African Air.Singapore AirlinesUnited Airlines

如果遇到server certificate問題,可以參考這個link的解決方案: http://code.naishe.in/2011/07...

總結

以上是生活随笔為你收集整理的java服务器http post_使用Java程序通过http post访问ABAP Netweaver服务器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。