0
當我向我的API發出POST請求時,我在RequestException.php第107行中得到ServerException。我收到以下錯誤 - 服務器錯誤:POST http://10.10.1.40:3000/auth/register
導致500 Internal Server Error response: {"statusCode":500,"errorMessage":"[object Object]"}
。 我試過從REST客戶端發送郵件請求,它工作。 以下是跟蹤laravel guzzlehttp - RequestException.php中的服務器異常
in RequestException.php line 107 at RequestException::create(object(Request), object(Response)) in Middleware.php line 65
at Middleware::GuzzleHttp\{closure}(object(Response)) in Promise.php line 199
at Promise::callHandler('1', object(Response), array(object(Promise), object(Closure), null)) in Promise.php line 152
at Promise::GuzzleHttp\Promise\{closure}() in TaskQueue.php line 60
at TaskQueue->run(true) in Promise.php line 240
at Client->request('POST', 'http://10.10.1.40:3000/auth/register', array('body' => '{"firstName":"abc","lastName":"ab"}')) in RegisterController.php line 30
at RegisterController->postRegisterForm(object(Request))
以下是我的控制器代碼
class RegisterController extends Controller{
public function postRegisterForm(Request $request){
$jsonData = json_encode($_POST);
$client = new Client();
$res = $client->request('POST','10.10.1.40:3000/auth/register', ['body' => $jsonData]);
echo $res->getStatusCode();
echo $res->getBody();
}
}
有什麼建議?
您可以發佈RegisterController的代碼嗎? –
在您的問題中發佈這個 –
我的第一個猜測是您的服務器不滿意它發送的請求。通常,請求的配置方式是通知服務器內容類型爲json。如果你調用$ response = $ client-> request('POST',$ uri,['json'=> $ jsonEncodableData,'debug'=> true,]),會發生什麼? –