我正在调用 FluidSurvey 的 API。当我发出 POST 请求时……它在 fluidSurvey 上发布请求,但我没有收到 JSON 响应。相反,它什么也不返回。有什么建议吗??
我的控制器代码
public class fluidSurvey{
public String tst{set;get;}
public String result{get;set;}
public PageReference chk() {
getData();
return null;
}
public void getData(){
String apiKey = 'xxxxxx';
String pwd = 'xxxxxx';
String u = 'https://app.fluidsurveys.com/api/v2/surveys/survey_id/responses/';
HttpRequest req = new HttpRequest();
Http http = new Http();
HTTPResponse res;
try{
req.setEndPoint(u);
req.setTimeout(2000);
req.setMethod('POST');
Blob headerValue = Blob.valueOf(apikey + ':' + pwd);
String authorizationHeader = 'Basic '+ EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
req.setHeader('Content-Type', 'application/json');
req.setHeader('Content-Length','31999');
res = http.send(req);
tst= res.toString();
catch(Exception e){
System.debug('Callout error: '+ e);
System.debug(tst+'--------'+res);
}
}
}
Apex 页面代码是
<apex:page controller="fluidSurvey">
<apex:form >
<apex:pageBlock title="New Fluid Surveys API">
<apex:outputText value="{!tst}"></apex:outputText><br/>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Submit" action="{!chk}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
和 api 文档链接是http://docs.fluidsurveys.com/api/surveys.html#getting-a-list-of-surveys ..