2016-03-21 11 views
2

ReactNative爲我提供了發送httpRequest的方法。body的屬性包括我要發送到服務器的參數。但是我無法獲取參數我server.My碼在這裏:取回ReactNative無法將主體中的副本傳遞到服務器

fetch(`${keys.api}/login`, 
     { 
      method: 'POST', 
      body: JSON.stringify({ 
       username: this.state.username, 
       password: this.state.password, 
      }), 
      headers: { 
       'Accept': 'application/json', 
       'Content-Type': 'application/json', 
      }, 

     } 
    ).then((response) => { 
     if(response._bodyText == 'success') { 
      this.props.resetToRoute({ 
       name: '主頁', 
       component: Main, 
       hideNavigationBar: true, 
      }); 
     } else { 
      this.cancelLogin(); 
     } 
    }).catch((error) => { 
     console.warn(error); 
     this.cancelLogin(); 
    }); 

在我的J2EE Web服務器控制檯打印消息: The httpRequest message

有一個在我的HttpRequest(換句話說,身體無法提供任何參數任何參數),我需要幫助。 在URL中顯示我的用戶名和密碼是危險的。

回答

-1

我曾兩次在碼頭 - 8.1在不同的條件下
首先,你應該知道,它沒有任何與之反應母語
fetch將數據放在身體頭「有效載荷」當客戶遇到的問題做了一個request.i以爲碼頭 - 8.1不支持從有效載荷頭 獲取數據,改變方式 Getting request payload from POST request in Java servlet將有助於
或可能使用websockt或XMLHttpRequest對象發送一個請求

// Read from request 
StringBuilder buffer = new StringBuilder(); 
BufferedReader reader = request.getReader(); 
String line; 
while ((line = reader.readLine()) != null) { 
    buffer.append(line); 
} 
String data = buffer.toString() 
+0

請inclu de相關的代碼部分從外部鏈接到代碼體中。 –

相關問題