Laravel 404帖子

时间:2014-02-12 03:15:19

标签: php android laravel

如果我使用Route :: post,它将不会检测到post请求。但是如果我使用Route :: any,它会将其检测为post。这只适用于“/ api / wish / {fbId} / edit”

Route::get('/', function()
{
    return View::make('hello');
});

/* 
 * API ROUTES
 */

 /* WISH API */

Route::get('/api/wish/add', function(){
    return View::make('hello');
});

Route::get('/api/wish/{fbId}/feed', 'WishApiController@getFeed');
Route::get('/api/wish/{fbId}/mine', 'WishApiController@getMine');
Route::post('/api/wish/{fbId}/create', 'WishApiController@postCreate');
Route::any('/api/wish/{fbId}/edit', 'WishApiController@postEdit'); // TODO: why doesn't it work if I choose post?

Route::get('/api/{fbId}/friends', 'UserApiController@getFriendsUsingApp');
Route::get('/api/{fbId}/{friendId}/follow', 'UserApiController@follow');
Route::get('/api/{fbId}/{friendId}/unfollow', 'UserApiController@unfollow');

Route::get('/api/wish/{fbId}/remove/{wishId}', 'WishApiController@getRemove');


Route::get('/wish/{wishId}', 'WishController@getWish');

请求来自Android应用程序:

    HttpClient httpClient = new DefaultHttpClient();
    HttpContext localContext = new BasicHttpContext();

    String fbid = SessionUser.getInstance(context).getFbId();
    String access_token = SessionUser.getInstance(context).getToken();
    String url = context.getString(com.somedomain.someproduct.R.string.api_url) + "wish/" + fbid + "/edit";

    Log.v(DEBUG,url);

    HttpPost httpPost = new HttpPost(url);

    MultipartEntityBuilder entity = MultipartEntityBuilder.create();        
    //entity.setMode(HttpMultipartMode.RFC6532);



    boolean success = true;
    try {

        // id
        String id = Wish.this.getId();
        if(id!=null)
            entity.addTextBody("id", id,ContentType.TEXT_PLAIN);
        else{
            success=false;
        }


        // name
        String name = Wish.this.getName();
        if(name!=null)
            entity.addTextBody("name", name,ContentType.TEXT_PLAIN);
        else{
            success=false;
            error=context.getString(R.string.no_name);
        }


        // desc
        String desc = Wish.this.getDesc();
        if(desc!=null)
            entity.addTextBody("desc", desc,ContentType.TEXT_PLAIN);

        // price
        String price = String.valueOf(Wish.this.getPrice());
        if(price!=null)
            entity.addTextBody("price", price,ContentType.TEXT_PLAIN);


        // access_token
        if(access_token!=null)
            entity.addTextBody("token", access_token,ContentType.TEXT_PLAIN);
        else{
            success=false;
            Log.e("CAPUTRE", "No Token");
        }

        // addr
        String addr = Wish.this.getAddr();
        if(addr!=null)
            entity.addTextBody("addr", addr);


        if(success){
            httpPost.setEntity(entity.build());


            HttpResponse response = httpClient.execute(httpPost, localContext);


            int statusCode = response.getStatusLine().getStatusCode();
            if(statusCode==200){



                String result = EntityUtils.toString(response.getEntity());
                Log.v(DEBUG,"result: "+statusCode);
                Log.v(DEBUG,result);

                JSONObject json =  new JSONObject(result);
                success = json.getBoolean("success");
                error = json.getString("error");
                JSONObject jsonResult = json.getJSONObject("result");
                if(jsonResult!=null){
                    Wish.this.setName(jsonResult.optString("name",""));
                    Wish.this.setDesc(jsonResult.optString("desc",""));
                    Wish.this.setAddr(jsonResult.optString("addr",""));
                    Wish.this.setPrice(Float.valueOf(jsonResult.optString("price", "0")));
                }

            }else{
                success = false;
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
        success = false;
    }

0 个答案:

没有答案