我無法連接到通過我敲打的小球衣客戶端測試在遠程計算機上運行的服務。Jersey客戶端無法連接到遠程計算機(502 Bad Gateway)
我能夠連接和POST成功使用捲曲,像這樣:
curl -X POST -T test.txt -H "Content-Type: application/octet-stream" http://remote-machine:11181/data?start=123
我已經成立了remote-machine
服務愉快地接受了這一點,並正常工作,但處理完全相同的URI時我通過我的球衣客戶端實現收到以下異常:
com.sun.jersey.api.client.UniformInterfaceException: POST http://remote-machine:11181/data?start=123 returned a response status of 502 Bad Gateway
at com.sun.jersey.api.client.WebResource.voidHandle(WebResource.java:707)
at com.sun.jersey.api.client.WebResource.access$400(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:553)
我的球衣客戶如下:
public static void main(String[] args) throws IOException {
if (args.length < 2) {
System.err.println("Usage: " + TestJerseyClient.class.getName() + " <uri> <input file>");
System.exit(-1);
}
File file = new File(args[1]);
if (!file.exists()) {
System.err.println("File not found: " + file.getAbsolutePath());
System.exit(-2);
}
URI uri = URI.create(args[0]);
Client client = new Client();
client.setChunkedEncodingSize(16 * 1024);
FileInputStream stream = new FileInputStream(file);
try {
System.out.println("Sending " + file.getPath());
client.resource(uri).type(MediaType.APPLICATION_OCTET_STREAM).post(stream);
System.out.println("Done");
} catch (Exception e) {
e.printStackTrace();
} finally {
Closeables.closeQuietly(stream);
}
}
任何幫助將不勝感激關於爲什麼我的球衣客戶端,一旦被給予與cURL相同的URI,得到這些502錯誤的網關錯誤。
(我想這或許是一個代理問題,而是讓球衣拿起他們作爲捲曲似乎,我不知道。)
這對我的工作很大,依賴是 COM .sun.jersey.contribs jersey-apache-client 您選擇的版本應該與您現有的jersey-client版本相匹配上 –
2015-10-23 11:06:24