Aşağıdaki java kodunu bir uzak url'ye POST xml verisine kullandım ve yanıtı aldım. Burada, giriş olarak bir xml dosyası kullanıyorum. İhtiyacım olan şey, bir dosyayı değil, bir xml olarak iletmektir ... bunu yapabilir miyim? Birisi bana yardım edebilir mi? Çok teşekkürler!java kullanarak POST xml verileri
Java kodu
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
public class xmlToString {
public static void main(String[] args) {
String strURL = "https://simulator.expediaquickconnect.com/connect/ar";
String strXMLFilename = "xmlfile.xml";
File input = new File(strXMLFilename);
PostMethod post = new PostMethod(strURL);
try {
post.setRequestEntity(new InputStreamRequestEntity(
new FileInputStream(input), input.length()));
post.setRequestHeader("Content-type",
"text/xml; charset=ISO-8859-1");
HttpClient httpclient = new HttpClient();
int result = httpclient.executeMethod(post);
System.out.println("Response status code: " + result);
System.out.println("Response body: ");
System.out.println(post.getResponseBodyAsString());
} catch (IOException e) {
e.printStackTrace();
} finally {
post.releaseConnection();
}
}
}
GÜNCELLEME: Ben
Çok teşekkürler, bence bu benim problemimi çözüyor ... :) –
Bu dint benim için çalışıyor. lütfen bu soruya yardım edin http://stackoverflow.com/questions/32884587/how-to-sent-xml-file-endpoint-url-in-restful-web-service/32884767#32884767 –
XML anahtar değerini nasıl zarif bir şekilde oluşturabilirim? saf dizeleri kullanmak yerine çiftler? – therealprashant