Oauth Post发送xml数据

时间:2019-07-08 09:51:11

标签: java json oauth

我无法发送获取和发布请求,但无法将xml数据作为文件发送。

我遇到以下错误。

1039为资源版本ID 158,767,696解析XML时发生错误

私有静态字符串sendOAuth1PostRequest(字符串url,字符串ConsumerKey,字符串sharedSecret,地图标题,地图bodyParams){

   BaseProtectedResourceDetails prd = new BaseProtectedResourceDetails();
   prd.setId("oauth");
   prd.setConsumerKey(consumerKey);
   prd.setSharedSecret(new SharedConsumerSecretImpl(sharedSecret));
   prd.setAdditionalRequestHeaders(headers);
   OAuthRestTemplate restTemplate = new OAuthRestTemplate(prd);


    String result = "";
    try {
        LinkedMultiValueMap<String, Object> param = new LinkedMultiValueMap<>();

        /*
          for(Entry<String, String> data:bodyParams.entrySet())
          {
              if(data.getKey().equals("file"))
              param.add(data.getKey(), data.getValue());
          }

        */
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);

        String fileData = "";

        for(Entry<String, String> data:bodyParams.entrySet())
        {

            //if(!data.getKey().equals("file"))
            builder.queryParam(data.getKey(), data.getValue());
            //else
                //fileData =  data.getValue();
        }

        System.out.println("--->"+builder.build().encode().toUri());

        HttpHeaders header = new HttpHeaders();
        header.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

        HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(param, header);



        ResponseEntity<String> responseEntity = restTemplate.exchange(builder.build().encode().toUri(),
                HttpMethod.POST, requestEntity, String.class);
        System.out.println("Response Entity is  >>> " + responseEntity);
        HttpStatus statusCode = responseEntity.getStatusCode();
        System.out.println("statusCode >> " + statusCode);
        if (statusCode == HttpStatus.ACCEPTED) {
            System.out.println("Status code is 200");
            result = responseEntity.getBody();

            //Adding in order to get the response status
            if(result==null||result.equals(""))
            {
                result = responseEntity.getStatusCode().toString();
            }

        }
        System.out.println("Response is " + result);

        System.out.println("Before printing respose");
    } catch (HttpClientErrorException e) {
        System.out.println(e.getResponseBodyAsString());
    }

    return result;

0 个答案:

没有答案