V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  RedBeanIce  ›  全部回复第 7 页 / 共 53 页
回复总数  1058
1 ... 3  4  5  6  7  8  9  10  11  12 ... 53  
@RedBeanIce

apache http ,,,伪代码
```
// 执行请求
CloseableHttpResponse response = httpClient.execute(post, new BasicHttpContext());
// 返回的状态 200 404 等等
int statusCode = response.getStatusLine().getStatusCode();

HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
result = IOUtils.toString(instream, StandardCharsets.UTF_8);
}
if (statusCode != 200) {
logger.info("request url failed, http code={}, url={}, result={}", response.getStatusLine().getStatusCode(), url, result);
return null;
}


result 里面就是,成功信息,或者是异常信息

```
@RedBeanIce

apache http ,,,伪代码
```
// 执行请求
CloseableHttpResponse response = httpClient.execute(post, new BasicHttpContext());
// 返回的状态 200 404 等等
int statusCode = response.getStatusLine().getStatusCode();
int statusCode = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
result = IOUtils.toString(instream, StandardCharsets.UTF_8);
}
if (statusCode != CONNCET_SUCCESS) {
logger.info("request url failed, http code={}, url={}, result={}", response.getStatusLine().getStatusCode(), url, result);
return null;
}
if (statusCode != 200) {
logger.info("request url failed, http code={}, url={}", response.getStatusLine().getStatusCode(), url);
return null;
}



```
@xiaokongwu

apache http ,,,伪代码
```
// 执行请求
CloseableHttpResponse response = httpClient.execute(post, new BasicHttpContext());
// 返回的状态 200 404 等等
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
logger.info("request url failed, http code={}, url={}", response.getStatusLine().getStatusCode(), url);
return null;
}
```
如果像是上述代码获取,,则只能获取到 bad request


报错都在日志打印里面,org.apache.http.wire ,carrier 字段有问题
@hmmm000

```
请求方式

HttpEntity<String> request = new HttpEntity<>(parse.toJSONString(), headersV2);
String personResultAsJsonStr = null;
try {
personResultAsJsonStr = restTemplate.postForObject(url, request, String.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println(personResultAsJsonStr);

```

```
打印

19:05:22.927 [main] DEBUG org.springframework.web.client.RestTemplate - Created POST request for "https://marketplace.walmartapis.com/v3/orders/108829823812146/shipping"
19:05:22.928 [main] DEBUG org.springframework.web.client.RestTemplate - Setting request Accept header to [text/plain, application/json, application/cbor, application/*+json, */*]
19:05:22.929 [main] DEBUG org.springframework.web.client.RestTemplate - Writing [{"orderShipment":{"orderLines":{"orderLine":[{"lineNumber":"1","orderLineStatuses":{"orderLineStatus":[{"status":"Shipped","statusQuantity":{"amount":"1","unitOfMeasurement":"EACH"},"trackingInfo":{"carrierName":{"carrier":"Fedex"},"methodCode":"Standard","shipDateTime":1698132951000,"trackingNumber":"785444130107"}}]},"sellerOrderId":"FO231024144001001"}]}}}] using [org.springframework.http.converter.StringHttpMessageConverter@7a362b6b]
19:05:23.423 [main] DEBUG org.springframework.web.client.RestTemplate - POST request for "https://marketplace.walmartapis.com/v3/orders/108829823812146/shipping" resulted in 400 (Bad Request); invoking error handler
null
org.springframework.web.client.HttpClientErrorException: 400 Bad Request
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:118)
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:103)
at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:730)

```

但是我想要的是,,

"{"errors":{"error":[{"code":"INVALID_REQUEST_CONTENT.GMP_ORDER_API","field":"carrier","description":"Unsupported carrier 'Fedex' was specified in line number 1. Only pre-defined names are allowed for 'carrier.' For a list of acceptable carriers, see https://developer.walmart.com/api/us/mp/orders#operation/shippingUpdates . If you select 'otherCarrier' you must also provide the tracking URL.","info":"Request content is invalid.","severity":"ERROR","category":"DATA","errorIdentifiers":{"entry":[]}}]}}

它提示我,,,carrier 字段有问题。。(相关描述,请看开头)
@lsk569937453

请再看一下我的问题。我们问题不是 400 。

而是具体的详细的报错,仅仅体现在日志中,无法让 ta 体现在返参中。
@dyllen 确实,你是对的。请找到适合自己的代码编写方式。

业务开发,开源开发,是两种玩法。
162 天前
回复了 justdoit123 创建的主题 JavaScript JS 大数溢出问题
@mxT52CRuqR6o5

可以,但是最好不要这样子。

一个后端+略微入门前端的人认为,一个语言不支持大数,是不太合理的。
172 天前
回复了 RedBeanIce 创建的主题 武汉 [武汉-后端] 请问有公司招人么
182 天前
回复了 mky 创建的主题 问与答 被骗 3.7w,后续该怎么避免电信诈骗
让他们有什么不懂的,先问你。
不要相信其他的任何人。
186 天前
回复了 RedBeanIce 创建的主题 MySQL 日常操作 Mysql 数据库的最佳实践是什么
@eDeeraiD0thei6Oh 我不清楚 mysqldump ,或者是从文件导入到 mysql 里面去,能不能解决我的问题。

我印象中,mysqldump 导入几十万条数据时,也会很慢。

我先去试试!!!!!
186 天前
回复了 RedBeanIce 创建的主题 MySQL 日常操作 Mysql 数据库的最佳实践是什么
@eDeeraiD0thei6Oh

比如是哪一些方面呢,我去学习一下。
186 天前
回复了 RedBeanIce 创建的主题 MySQL 日常操作 Mysql 数据库的最佳实践是什么
@cyningxu
额,,直接使用命令行么。
有点难以操作,容我去学习一下。。
@Toby23 如果你也是互联网从业者,请注意一点。

要感性的对待人世间,也要理性的解决人世间的问题。
@Toby23
得思考一下,为什么宁愿相信网上,也不相信你。
1 ,一般情况下,老一辈会有一种不愿意被压制的反抗。
认为一味的听儿子的,听什么什么身边某个人的,就是一种压制的表现。所以很多老一辈的婆媳关系很糟糕。
就是不想被压制,想要压制别人。。。。

解决的办法只有一个,让他们明白,要去做正确的事情,而不是因为压制,不压制。而做出无脑的反抗。

2 ,让他们相信你是对的,可以做出正确的选择,一家人向着正确的目标走去。

3 ,信任的维系是艰难的,请好好的做出你的选择。
一步错,信任就直接断掉了。

其他。。。。。。。。。。。。。。。
如楼上所说,要多和父母沟通。

1 ,让他们有什么问题,直接问你。(对于现在世界的各种问题)
2 ,他们有很多问题,请不要感到厌烦。
3 ,
@rsyjjsn 诡辩的。
188 天前
回复了 breeze2001 创建的主题 Java 求大佬推荐一下微服务学习路线
楼上的说有 k8s 情况下,不要学 cloud ,请注意一点。

国内 99%的地方,都是 cloud ,学 k8s 去哪个公司用呢。
192 天前
回复了 tim9527 创建的主题 问与答 怎么平衡与家里人观念的差异?
@smileawei
我爸妈是叛逆的,我也是叛逆的。
我爸妈不听我爷爷奶奶的,我不听我爸妈的。

目前我和爸妈=差不多家庭和谐,,,,,我爸妈和爷爷奶奶关系=有点糟糕。
1 ... 3  4  5  6  7  8  9  10  11  12 ... 53  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1176 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 41ms · UTC 18:27 · PVG 02:27 · LAX 11:27 · JFK 14:27
Developed with CodeLauncher
♥ Do have faith in what you're doing.