2012-08-29 47 views
7

我們使用Phil Sturgeons cool Restful API framework for codeigniter構建了我們的API,該工具已準備就緒,並且可用作我們移動應用實施的一部分。Restful API codeigniter - JAVA問題

我們當使用API​​在Java中

httpConnection = (HttpConnection) Connector.open(url, Connector.READ, true); 
// Set content type by given parameter...... 
httpConnection.setRequestProperty("Accept", contentType); 
httpConnection.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/FCLDC-1.0"); 
httpConnection.setRequestProperty("Content-Type", contentType); 
httpConnection.setRequestProperty("TK-API-KEY", UrlFactory.TK_API_KEY); 

// httpConnection.setRequestProperty("Model", 
// StyleUtil.getDeviceModel()); 
if (httpConnection.getResponseCode() == 302) 
{ 
    String redirectUrl = httpConnection.getHeaderField("Location"); 
    httpConnection = (HttpConnection) Connector.open(redirectUrl, Connector.READ_WRITE, true); 
} 

if (httpConnection.getResponseCode() == HttpConnection.HTTP_OK) 
{ 
    io = httpConnection.openInputStream(); 

    int ch; 
    while ((ch = io.read()) != -1) 
    { 
    bo.write(ch); 
    } 

} 

httpConnection.getResponseCode()無法獲取狀態代碼,並返回一個畸形的異常有一個問題。我們的API服務器是NGINX。

+1

你可以發佈它返回的內容嗎? – Broncha

+0

你有沒有得到這個工作? – seangates

+0

如果[CI](http://codeigniter.com)沒有必要,您可以給[jabsorb](http://code.google.com/p/jabsorb/)一個機會。 – quantme

回答

1

如果頭部字段設置不正確,則會引發MalformedException。請檢查不同的標題和不同的用戶代理。嘗試使用 httpConnection.setDoOutput(true);