如何将此curl命令转换为java HttpGet

时间:2017-12-20 07:17:45

标签: java http curl nullpointerexception

有这样一个卷曲命令:

curl -k -X GET -H "Accept: Application/json" -H "Content-Type: application/json" -u XXX:YYY https://someUrl/customer/v1/85230000105

其中XXX是用户名,YYY是密码,85230000105是需要发送到Web服务的参数

我尝试编写这样的java代码:

            HttpGet request = new HttpGet("https://someUrl/customer/v1/85230000105");
        request.addHeader("content-type", "application/json");
        request.addHeader("accept", "application/json");
        request.addHeader("username", "XXX");
        request.addHeader("password", "YYY");

这种转换是否正确?当我直接运行curl命令时,我可以获得回复成功,但是当我做

httpResponse = httpClient.execute(request);

这会引发异常,这里是异常图片: enter image description here

请帮我找到原因。

0 个答案:

没有答案