0

REST API json オブジェクトに投稿しようとしていますが、responce 404 を受け取り続けていますが、URL は正常に機能しています。なぜこれが起こっているのか誰か教えてもらえますか?

これが私のコードです:

new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {

                HttpPost request = new HttpPost(
                        "http://grpsvil-webservice.si2001.it/RestChannelApp.svc/CheckCoupon");
                // request.setHeader("Accept", "application/json");
                request.setHeader("Accept", "application/json");
                request.setHeader("Content-type", "application/json");

                try {
                    // Build JSON string
                    JSONStringer vehicle = new JSONStringer()
                            .object()
                            .key("CouponVerificationCode")
                            .value("adf")
                            .key("ApiKey")
                            .value("adfadf123")
                            .key("Token")
                            .value("fgsg342==")
                            .endObject();
                    Log.v("--", vehicle.toString());
                    StringEntity entity = new StringEntity(vehicle.toString());

                    request.setEntity(entity);

                    // Send request to WCF service
                    DefaultHttpClient httpClient = new DefaultHttpClient();
                    HttpResponse response = httpClient.execute(request);
                    int resCode = response.getStatusLine().getStatusCode();
                    Log.v("--", response.getStatusLine().getStatusCode() + "");

                    if (resCode == 200) {

                        Toast.makeText(getApplicationContext(),
                                response.getStatusLine().getStatusCode() + "",
                                Toast.LENGTH_LONG).show();
                        BufferedReader in = new BufferedReader(
                                new InputStreamReader(response.getEntity()
                                        .getContent()));
                        String line = "";
                        StringBuffer returnFromServer = new StringBuffer();

                        while ((line = in.readLine()) != null) {
                            returnFromServer.append(line);
                        }
                        // Toast what we got from server
                        Log.v("--", "!@# " + returnFromServer.toString());

                        if (entity != null) {
                            entity.consumeContent();
                        }

                    }
                } catch (Exception e) {
                    // TODO: handle exception
                }
                Intent i = new Intent(Splash.this, Login.class);
                startActivity(i);
                finish();
                return null;
            }
4

4 に答える 4

1

http://grpsvil-webservice.si2001.it/RestChannelApp.svc?WSDLからすべての WSDL を取得すると、定義したすべての操作を確認できます。

CheckCoupon はありませんが、CheckPromotionalCodeがあります。

それはありますか?

于 2014-02-27T14:59:23.160 に答える
1

URL は 404 not found を返します。ブラウザに派手なエラー テキストが表示されるからといって、ステータス コードが 200 OK であるとは限りません。これは私が得る HTTP 応答です:

Status Code: 404 Not Found
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: GET,PUT,POST,DELETE
Age: 0
Cache-Control: private
Connection: Keep-Alive
Content-Length: 1565
Content-Type: text/html; charset=UTF-8
Date: Thu, 27 Feb 2014 14:58:03 GMT
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
access-control-allow-origin: *
x-powered-by: ASP.NET
于 2014-02-27T14:59:26.940 に答える