android如何将POST json请求发送到Laravel Framework

时间:2015-06-09 15:55:21

标签: php android laravel

嗨我正在做android和laravel框架.. 但是当我发布方法并通过POST将json发送到laravel api时...它将给出500结果..请帮助..

这是我发送帖子数据的asynctask之一..假设sendJsonObj是一个带有值的jsonobject ..

URL url = new URL("http://dexter-laravelframe.rhcloud.com/register");

        urlConnect = (HttpURLConnection) url.openConnection();
        urlConnect.setRequestMethod("POST");
        urlConnect.setConnectTimeout(10000);
        urlConnect.setRequestProperty("Content-Type", "application/json");
        urlConnect.setRequestProperty("x-csrf-token", Model_Application.token_csrf);
        urlConnect.connect();

        OutputStreamWriter outWrite = new OutputStreamWriter(urlConnect.getOutputStream());
        outWrite.write(sendJsonObj.toString());
        outWrite.flush();
        outWrite.close();

        int code = urlConnect.getResponseCode();`

在我的Laravel框架上..    routes.php文件 Route::post('/register', 'UserController@register');

UserController.php

public function register()
{
    $json = Input::json()->all();

    $resultJson = json_encode($json);

    echo $resultJson;

}

这将提供来自Laravel api的500响应代码..我希望它读取json数据..并将其发回...如果我使用Mozilla插件休息客户端,并在体内发送json数据..它给出200 ..

0 个答案:

没有答案