当通过HttpClient Android发布时,Laravel Rest身份验证

当我通过android HttpClient发布时,如何过滤laravel rest应用程序,只验证用户标识和正确的密码? 我试图找到最好的方法,但没有得到最好的样本。

这是我的代码:

public static int LogExceptionError(final ExceptionLog exceptionLog) {

        final HttpResponse[] response = new HttpResponse[1];
        new Thread(new Runnable() {
            public void run() {
                // Create a new HttpClient and Post Header
                HttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(AndroidHelperUtility.getBaseUrl("exceptionlog/create", AndroidHelperUtility.IS_DEBUG_MODE));
                try {

                    Gson gson = new Gson();
                    String jsonString = gson.toJson(exceptionLog);

                    JSONObject jsonObject = new JSONObject();
                    jsonObject = new JSONObject(jsonString);

                    JSONArray jsonArray = new JSONArray();
                    jsonArray.put(jsonObject);

                    // Post the data:
                    httpPost.setHeader("json", jsonObject.toString());
                    httpPost.getParams().setParameter("jsonpost", jsonArray);

                    // Execute HTTP Post Request
                    System.out.print(jsonObject);
                    HttpResponse httpResponseponse = httpClient.execute(httpPost);
                } catch (JSONException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }).start();

        if (response[0] != null) {
            return 1;
        } else {
            return 0;
        }
    }

Laravel控制器:

public function postCreate() {
        $json = $_SERVER['HTTP_JSON'];
        $data = json_decode($json);  
        $object = ExceptionLogService::create($data);
        return Response::json($object);

    }

服务等级:

class ExceptionLogService extends BaseService {

    public static function create($data) {
        $object = array(
            "refNumber" => $data->refNumber,
            "source" => $data->source,
            "userName" => $data->userName,
            "description" => $data->description
        );
        ExceptionLogRepository::create($object);
        return $object;
    }
链接地址: http://www.djcxy.com/p/3735.html

上一篇: Laravel Rest Authentication when post via HttpClient Android

下一篇: How do you dynamically create a radio button in Javascript that works in all browsers?