我试图用假装发布json字符串

时间:2017-12-06 10:57:23

标签: json oauth feign

我试图使用假装发布一个json,但我从url得到一个错误,即没有发送参数。这是我的代码:

JSONObject jsonObject = new JSONObject();
    jsonObject.put("name", "Rabbit SEO");
    jsonObject.put("price", "10");
    jsonObject.put("test", "true");
    jsonObject.put("return_url", "https://www.rabbitseo.com/shopifyPaidGuest");
    String content = jsonObject.toString();
    System.out.println("content = " + content);
    String result = myClient.postRecurringPayment(content);



 @RequestLine("POST /admin/recurring_application_charges.json")
    @Headers("Content-Type: application/json")
    String postRecurringPayment(String content);



return Feign.builder()
         .requestInterceptors(requestInterceptors)
         .target(MyApiClient.class, myShopifyUrl);

I tried also with the gson decoder and encoder:


return Feign.builder()
            .decoder(new GsonDecoder())
            .encoder(new GsonEncoder())
            .requestInterceptors(requestInterceptors)
            .target(MyApiClient.class, myShopifyUrl);

错误: feign.FeignException:status 400读取MyApiClient#postRecurringPayment(String);内容: {"错误":{" recurring_application_charge":"必需参数丢失或无效"}}     at feign.FeignException.errorStatus(FeignException.java:62)     at feign.codec.ErrorDecoder $ Default.decode(ErrorDecoder.java:91)     在feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:126)     at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:74)     在feign.ReflectiveFeign $ FeignInvocationHandler.invoke(ReflectiveFeign.java:94)     在com.sun.proxy。$ Proxy4.postRecurringPayment(未知来源)     at com.test.TestOauth.testShopifyProducts2(TestOauth.java:49)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:44)     在org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)     在org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)     在org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)     在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)     在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)     在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:193)     在org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:52)     在org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)     在org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:42)     在org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:184)     在org.junit.runners.ParentRunner.run(ParentRunner.java:236)     在org.junit.runner.JUnitCore.run(JUnitCore.java:157)     在com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)

1 个答案:

答案 0 :(得分:0)

查看日志http错误代码400表示BadRequest

"errors":{"recurring_application_charge":"Required parameter missing or invalid"

您必须将recurring_application_charge作为JSON的一部分传递,才能被API接受

但是,您需要发布完整的错误日志,而MyClient类将为您提供更多建议。