2014-01-07 3 views
0

POST 메소드로 Android 애플리케이션에서 WS 메소드를 호출하려고합니다. 내가 무슨 짓을 :안드로이드와 포스트 콜에서 코드 400 오류

String urlServer = GlobalSession.IP + "insert_reportByte"; 
      Log.d("[Report]", "url address: " + urlServer); 
      URL url = new URL(urlServer); 
      HttpURLConnection connection = (HttpURLConnection) url 
        .openConnection(); 

      connection.setDoInput(true); 
      connection.setDoOutput(true); 
      connection.setUseCaches(false); 

      connection.setRequestMethod("POST"); 

      connection.setRequestProperty("Connection", "Keep-Alive"); 
      connection.setRequestProperty("Content-Type", 
        "multipart/form-data"); 

      DataOutputStream outputStream = new DataOutputStream(
        connection.getOutputStream()); 

      outputStream.write(outputByteArray, 0, outputByteArray.length); 
      int serverResponseCode = connection.getResponseCode(); 
      String serverResponseMessage = connection.getResponseMessage(); 
      Log.d("ServerCode", "" + serverResponseCode); 
      Log.d("serverResponseMessage", "" + serverResponseMessage); 
      outputStream.flush(); 
      outputStream.close(); 

     } catch (Exception ex) { 
      // ex.printStackTrace(); 
      Log.e("[Report] --- /!\\ Error: ", ex.getMessage()); 
     } 
     return result; 

그래서이 서비스에 바이트 배열을 보내도록 하죠. 하지만 400 오류 응답이 있습니다. 제 질문은 그러한 문제의 세부 사항을 얻는 방법입니다.

[OperationContract] 
    [WebInvoke(Method = "POST", 
     UriTemplate = "insert_reportByte", 
     BodyStyle = WebMessageBodyStyle.Bare)] 
    void insert_reportByte(byte[] image); 

: 그런 식으로 나는 서버의 로그에 아무것도 찾을 수 있으며 (ASP.NET에서)

는 WS가 정의 ... 나는 세부 사항이없는 경우 디버깅하기 어렵다 때문에 호출 된 메서드는 다음과 같습니다.

public void insert_reportByte(byte[] image) 
    { 
     MyEntities entities = new MyEntities(); 
     String base64stringimage = System.Convert.ToBase64String(image,0,image.Length); 

     entities.insert_report("admin", "0614141.107346.2001", "test", base64stringimage, "test"); 

    } 

무엇이 잘못 되었습니까?

감사합니다.

+0

Postman이라는 크롬 확장 프로그램이 도움이 될 수 있습니다. 동일한 호출을하지만 브라우저에서 URL/params 매핑에 WS 오류를 따로 두십시오. – axierjhtjz

+0

해당 방법을 사용하여 이미지를 WS로 보내려고하므로 "파일이 너무 큼"413 오류가 발생했습니다. – Derbie

+0

나는 귀하의 문제가 귀하의 WS 내부에 상주한다고 생각하는데, 요청에 따라 허용되는 최대 허용 바이트 수는 제한되어 있습니다. 질문에 WS에 대한 자세한 정보를 추가 할 수 있습니까? – axierjhtjz

답변

0

applicationHost.config 파일의 uploadReadAheadSizemaxReceivedMessageSize 매개 변수를 변경해야합니다. 여기

는 피고측은 당신이 더 잘 처리하기위한 uploadReadAheadSizemaxReceivedMessageSize 매개 변수를 변경해야하는 이유를 설명대로

http://forums.iis.net/t/1169257.aspx?Request+Entity+Too+large+413+error+

이 링크도 유용 할 수 있습니다에 대해 이야기 스레드를 가지고 파일 업로드.

http://www.codeproject.com/Articles/521725/413-Request-Entity-Too-Large

UPDATE는 HTTP 요청에이 라이브러리를 사용해보십시오. 그것은 당신이 서버에 나쁜 요청을 보내는 것 같습니다. 나는 ws가 예상하는 매개 변수와 관련이 있다고 생각하지 않지만, 안드로이드 애플 리케이션이 보낸 http 헤더. https://github.com/loopj/android-async-http

는 도움이되기를 바랍니다. :)