【问题标题】:Jsoup sends application/x-www-form-urlencoded instead of jsonJsoup 发送 application/x-www-form-urlencoded 而不是 json
【发布时间】:2023-03-21 14:02:01
【问题描述】:

我正在尝试使用 Jsoup 将数据作为 json 发布到 api,但是 api 给我一个错误提示

There was an unexpected error (type=Unsupported Media Type, status=415).
Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

Jsoup 请求:

Jsoup.connect(apiConfiguration.getHttpBaseAddress()+url)
                .validateTLSCertificates(false)
                .maxBodySize(0)
                .timeout(180000)
                .ignoreHttpErrors(true)
                .header("Authorization", apiConfiguration.getLoginString())
                .header("Content-Type", "application/json")
                .header("cache-control", "no-cache")
                .method(Connection.Method.POST)
                .requestBody(reqBodyStr)//POJO, parsed with Gson --> String
                .execute();

可能Jsoup没有改变内容类型?我也试过先设置requestBody,再设置内容类型,但都是一样的。

【问题讨论】:

    标签: json jsoup


    【解决方案1】:

    是的,是 Jsoup,有一个拉取请求来解决这个问题, 希望将包含在下一个版本中(1.9.2 之后)

    https://github.com/jhy/jsoup/pull/734

    【讨论】:

      猜你喜欢
      • 2017-09-11
      • 2019-05-04
      • 2017-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-09
      相关资源
      最近更新 更多