【问题标题】:discogs post https://api.discogs.com/marketplace/listings? returned a response status of 422 nulldiscogs 发布 https://api.discogs.com/marketplace/listings?返回响应状态 422 null
【发布时间】:2021-12-19 07:34:40
【问题描述】:

我正在尝试在 java 中发布 api.discogs.com/marketplace/listings?...。

当我尝试发布新列表帖子时,结果是“返回了 422 null 的响应状态”。

"422 无法处理的实体 您的请求格式正确,但请求正文在语义上存在问题。这可能是由于 JSON 格式错误、参数丢失或类型错误,或者尝试执行没有任何意义的操作。查看响应正文,了解有关问题的具体信息。”

“Invalid release_id:expected integer”显示为消息。

我的 get 方法有效,但 post 无效。

int release_id;
String condition;
int listing_id;
String sleeve_condition;
String comments;
String allow_offers;
string status;
String external_id;
String location;
string weight;
String format_quantity;
private Double price = Double.valueOf(0);

json = doPost("/marketplace/listings?release_id=" + product.getRelease_id() + "&sleeve_condition=" + product.getCondition() + "&price=" +product.getPrice());

"https://api.discogs.com/marketplace/listings?release_id=1113859&condition=poor&price=2000.0&status=Mint"



   WebResource webResource = initRest(restUrl);
    ClientResponse resp = webResource.type("application/json")
            .header("Authorization", "Discogs token=" + token)
            .header("JTLSyncTool/0.1", "+https://#####")
            .post(ClientResponse.class);

有人有想法吗?

谢谢大家!

【问题讨论】:

  • 请显示有效的POST字符串(doPost()的参数值)!
  • 请修正您问题中的 Java 代码!

标签: java post postdata discogs-api javahelp


【解决方案1】:

为了测试代码的工作情况,我直接写了如下。

json = doPost("/marketplace/listings?release_id="+1113859+"&status=Draft"
                      +"&condition="+"Mint%20(M)"+ "&price=" +2000.0);



 protected static JSONObject doPost(String restUrl) {
        JSONObject json = null;

        WebResource webResource = initRest(restUrl);
        ClientResponse resp = webResource.type("application/json")
                .header("Authorization", "Discogs token=" + token)
                .header("JTLSyncTool/0.1", "+https://www.####.de")
                .post(ClientResponse.class);
        json = parseRest(json, resp);
        if(resp.getStatus() > 250) {
            PersistenceHelper.addError(DiscogsApi.class.getName(), restUrl);
            PersistenceHelper.addError(DiscogsApi.class.getName(), resp.toString());
        }

        return json;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-09
    • 2021-01-27
    • 2017-10-25
    • 1970-01-01
    • 2019-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多