모바일 장치를 사용하여 서버 (vb.net)에 데이터를 게시하려고합니다. 나는이 Encosia article 및 sending JSON object with Android을 포함하여 클라이언트 측 (Android)에 대한 몇 가지 훌륭한 기사를 조사했습니다.vb.net asmx Android를 사용하여 HTTP-POST에서 JSON을 허용하는 WebService
내가 샘플 클래스를 만들었습니다
Public Class OneEvaluation
Private strEmail As String
Public Property email() As String
Get
Return strEmail
End Get
Set(ByVal value As String)
strEmail = value
End Set
End Property
Private strPassword As String
Public Property password() As String
Get
Return strPassword
End Get
Set(ByVal value As String)
strPassword = value
End Set
End Property
End Class
를 내가 내의 WebMethod를 만들었습니다
그것은 오류없이 (VS2008에 SP1)을 구축Public Class AsmxCodebehind
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function AndroidTest(ByVal JSON As OneEvaluation) As String '
Dim strSQLInsertCommand As String
' code block
Return "whatever"
End Function
. 안드로이드에 대한 응답이 없습니다. 'JSON as OneEvaluation'인수를 삭제하면 브라우저에 게시되고 HTML 반환을 제공합니다. 위의 코드로하지만 ... 오류는 다음과 같습니다 는 System.InvalidOperationException: AndroidTest Web Service method name is not valid. at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
참고로, 내 안드로이드 조각은 다음과 같습니다
final String URL = "http://www3.myurl.com/JSON/service.asmx/AndroidTest"
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
HttpResponse response;
JSONObject json = new JSONObject();
try{
HttpPost post = new HttpPost(URL);
json.put("email", email);
json.put("password", pwd);
StringEntity se = new StringEntity("OneEvaluation: " + json.toString());
// post.setEntity(se);
post.setHeader("Accept", "application/json");
post.setHeader("Content-type", "application/json; charset=utf-8");
// se.setContentEncoding((Header) new BasicHeader(HTTP.CONTENT_TYPE, "application/json; charset=utf-8"));
post.setEntity(new ByteArrayEntity(se.toString().getBytes("UTF8")));
// post.setHeader(OneEvaluation, value)
// ResponseHandler responseHandler = new BasicResponseHandler();
response = client.execute(post);
/* Checking response */
Log.v("TAG", " JSON onItemClick fired! Position:");
if(response!=null){
Log.v("TAG", " Response :" + response.toString());
// Toast.makeText(v.getContext(), response, Toast.LENGTH_LONG);
InputStream in = response.getEntity().getContent(); //Get the data in the entity
}
}
catch(Exception e){
e.printStackTrace();
createDialog("Error", "Cannot Estabilish Connection");
Log.v("TAG", " Cannot Estabilish Connection");
}
나는 (jQuery를 사용하여 제외) 모두 서버 측과 완벽한 예를 보지 못했다 클라이언트 측 (특히 안드로이드). 그래서 나는 다른 누군가의 주말을 구하기를 희망합니다!
내 다른 AJAX/JSON 서비스 (JSON을 반환하는 서비스 포함)가 vb (및 작동 중)에 있으므로 서버 측에서 C#을 사용하여 저항했습니다.
나는 서버 측 오류에 대한 도움을 요청하고 있으며, Android JSON HTTP_POST를 정리하기위한 제안 사항이 있습니다.
많은 분들께 미리 감사드립니다.
저는 POST에서 JSON을 보내고 있는지 확인하기 위해 Fiddler를 사용했습니다. Fiddler는 다음과 같이 내 게시물을 표시합니다.
POST http://www3.myweb.com/JSON/swUpdate.asmx/SaveProcedureList HTTP/1.1 Accept: application/json Content-type: application/json; charset=utf-8 Content-Length: 44 Host: www3.tidewatertechnology.com Connection: Keep-Alive User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4) Expect: 100-Continue {"OneEvaluation": {"email":"kiddin","password":"no"}}
– SolarBlitz