2017-06-13 20 views
0

私の角型アプリケーションで私の問題を解決することはできません。私はそんなに試したことがありますが、角度4から送信された投稿データの本文を読むことができません。誰かがプロブラムを見つけることができますか?とても素敵でしょう!PHPで角度からポストデータを取得できません

私のPHP-Apiにデータを送信するサービスがあります。関連する関数は次のようになります。私のAPIから

login(email: string, password: string): Observable<UserDto> { 

    let apiUrl = 'api/v1/login'; 
    let userAuthDto: UserAuthDto = new UserAuthDto(email, password); 

    let headers = new Headers({ 'Content-Type': 'application/json' }); 
    let options = new RequestOptions({ headers: headers }); 

    return this.http.post(apiUrl, { email, password }, options) 
        .map(res => res.json()) 
        .map(res => console.log(res)) 
        .map((data: any) => UserDto.fromJson(data[0])) 
        .do(res => { if (res.auth_success) { 
         localStorage.setItem('auth_token', res.token); 
        }}) 
        .catch(this.handleError); 
} 

関連するコードは次のようになります。

header("Content-Type: application/json"); 

//Get database connection 
$db = mysqli_connect("localhost", "******", "********", "*******"); 
if(!$db) { 
    exit("Alert: ".mysqli_connect_error()); 
} 

//Set connection charset to UTF-8 
mysqli_set_charset($db, "utf8"); 

$data = file_get_contents('php://input'); 
$test = $data; 
$resultArray = array(); 

$sqlQuery = "SELECT id, username FROM user WHERE id = 4"; 

//Database query 
$myresult = mysqli_query($db, $sqlQuery); 
while($row = mysqli_fetch_assoc($myresult)) 
{ 
    $row['auth_success'] = true; 
    $row['test'] = $test; 
    $resultArray[]=$row; 
} 

echo json_encode($resultArray); 

だけのテストのためだこと。しかし、問題は何でも私はfile_get_contents('php://input');は空の文字列です。何が問題なのか分かりますか?私はXAMPPを使用しています。

ありがとうございます!

答えて

0

ええ!わかった!

3日後にその問題を解決しようとして、私はそれを得た!誰かが同じ問題を抱えている可能性があるので、うまくいけば私はあなたを助けることができます:

問題はの文字ですです。

let apiUrl = 'api/v1/login/'; 

let apiUrl = 'api/v1/login'; 

...、すべてが動作します:

はジャストからAPI-URLを変更しました!

関連する問題