【发布时间】:2019-01-31 14:10:30
【问题描述】:
我正在向 API 服务器发帖,我收到以下回复:
Server Response: {"detail":"Authentication credentials were not provided."}
我正在用 Java 编写请求,但我不确定为什么它说没有提供凭据。
这是我的代码的 sn-p:
hconn.setRequestProperty("Content-Type", "application/json");
hconn.setRequestProperty( "Accept", "application/json" );
if( urlconn instanceof HttpsURLConnection )
{
String encoded = new String(Base64.getEncoder().encode( ( username + ":" + password).getBytes()));
String auth = "Basic " + encoded;
urlconn.setRequestProperty("Encoded Authorization", auth );
}
其中hconn 的类型为HttpURLConnection
这是你们需要的唯一相关的sn-p。有没有我想在这里设置的属性?
我知道服务器响应来自 Django 框架,但文档并不清楚发现需要什么来防止这种情况发生。
任何帮助表示赞赏。
【问题讨论】: