Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Web服务客户端应用程序_Java_Xml_Web Services - Fatal编程技术网

Java Web服务客户端应用程序

Java Web服务客户端应用程序,java,xml,web-services,Java,Xml,Web Services,有一个.NETWeb服务,我必须从本地应用程序发送XML数据。我的本地应用程序在Java和Sql上运行 Web服务正在接受xml类型。你能帮我吗?我该怎么办?有没有这个例子 我给出了java应用程序中的两个示例,您将一个文件发布到服务 Apache HttpClient: 谢谢 Shiva Kumar SSGoogle,你会发现大量的例子。不要期望如此,当你可以做同样的事情时,它会为你提供链接。我已经搜索了谷歌甚至youtube的教程。但我不太明白。我该怎么办。所以,如果有人以前做过同样的申请,

有一个.NETWeb服务,我必须从本地应用程序发送XML数据。我的本地应用程序在Java和Sql上运行


Web服务正在接受xml类型。你能帮我吗?我该怎么办?有没有这个例子

我给出了java应用程序中的两个示例,您将一个文件发布到服务

Apache HttpClient:

谢谢


Shiva Kumar SS

Google,你会发现大量的例子。不要期望如此,当你可以做同样的事情时,它会为你提供链接。我已经搜索了谷歌甚至youtube的教程。但我不太明白。我该怎么办。所以,如果有人以前做过同样的申请,他们可能会建议我。从你看到的或读到的东西中,你到底不明白什么?
String url = "https://yoururl.com"; 

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);

// add header
post.setHeader("User-Agent", USER_AGENT);

List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("xml", xmlString));

post.setEntity(new UrlEncodedFormEntity(urlParameters));

HttpResponse response = client.execute(post);
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + post.getEntity());
System.out.println("Response Code : " + 
                            response.getStatusLine().getStatusCode());

BufferedReader rd = new BufferedReader(
                new InputStreamReader(response.getEntity().getContent()));

StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
    result.append(line);
}

System.out.println(result.toString());
String url = "http://example.com";
String charset = "UTF-8";
String param1 = URLEncoder.encode("param1", charset);
String param2 = URLEncoder.encode("param2", charset);
String query = String.format("param1=%s&param2=%s", param1, param2);

URLConnection urlConnection = new URL(url).openConnection();
urlConnection.setUseCaches(false);
urlConnection.setDoOutput(true); // Triggers POST.
urlConnection.setRequestProperty("accept-charset", charset);
urlConnection.setRequestProperty("content-type", "application/x-www-form-urlencoded");

OutputStreamWriter writer = null;
try {
    writer = new OutputStreamWriter(urlConnection.getOutputStream(), charset);
    writer.write(query); // Write POST query string (if any needed).
} finally {
    if (writer != null) try { writer.close(); } catch (IOException logOrIgnore) {}
}

InputStream result = urlConnection.getInputStream();
// Now do your thing with the result.