首页 文章 精选 留言 我的

精选列表

搜索[服务],共10000篇文章
优秀的个人博客,低调大师

使用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 = <replace with your own application server url>; 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: <a href=’http://www.aa.com’ target=’_blank’>American Airlines</a><br /><a href=’http://www.aircanada.ca’ target=’_blank’>Air Canada</a><br /><a href=’http://www.airfrance.fr’ target=’_blank’>Air France</a><br /><a href=’http://www.alitalia.it’ target=’_blank’>Alitalia</a><br /><a href=’http://www.british-airways.com’ target=’_blank’>British Airways</a><br /><a href=’http://www.airpacific.com’ target=’_blank’>Air Pacific</a><br /><a href=’http://www.continental.com’ target=’_blank’>Continental Airlines</a><br /><a href=’http://www.delta-air.com’ target=’_blank’>Delta Airlines</a><br /><a href=’http://www.airberlin.de’ target=’_blank’>Air Berlin</a><br /><a href=’http://www.lufthansa.com’ target=’_blank’>Lufthansa</a><br /><a href=’http://www.laudaair.com’ target=’_blank’>Lauda Air</a><br /><a href=’http://www.jal.co.jp’ target=’_blank’>Japan Airlines</a><br /><a href=’http://www.nwa.com’ target=’_blank’>Northwest Airlines</a><br /><a href=’http://www.qantas.com.au’ target=’_blank’>Qantas Airways</a><br /><a href=’http://www.saa.co.za’ target=’_blank’>South African Air.</a><br /><a href=’http://www.singaporeair.com’ target=’_blank’>Singapore Airlines</a><br /><a href=’http://www.ual.com’ target=’_blank’>United Airlines</a> 如果遇到server certificate问题,可以参考这个link的解决方案: http://code.naishe.in/2011/07/looks-like-article-no-more-unable-to.html 本文来自云栖社区合作伙伴“汪子熙”,了解相关信息可以关注微信公众号"汪子熙"。

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册