0

我在 C 中使用 curl 将 HTTP 请求发送到具有多个版本的 Web API。根据用户代理,Web 服务器会发送 301 响应,并且 curl 会尝试遵循重定向。这一切都按设计工作,但有一种特殊情况会中断。

当我发送授权请求并且我没有指定域名(https://test.example/server而不是https://test.example.com/server)时,Web 服务器会将应用程序重定向到https: //test.example.com/serverv2,添加域名。但是重定向后第二次尝试的响应是 401,“无法从标头解析凭据”。如果我不省略域名,一切都会按预期进行,包括重定向,并且我的授权成功。

我的问题是:这是 curl 的内置功能还是错误?其次,是否有处理这种特殊情况的首选方法?

4

1 回答 1

0

来自 curl.h

/* Continue to send authentication (user+password) when following locations,
     even when hostname changed. This can potentially send off the name
     and password to whatever host the server decides. */
  CINIT(UNRESTRICTED_AUTH, LONG, 105)

我设置了这个选项,它解决了我的问题。有时你只需要多挖一点。:)

curl_easy_setopt (curl, CURLOPT_UNRESTRICTED_AUTH, 1);
于 2013-07-12T15:04:36.997 回答