Keine Antwort, wenn dabei eine HttpPost mit JSON

Habe ich einen submit-button erstellt, in dem ich den Aufruf der Methode "Ruf 2", die den code enthält
ein HttpPost mit JSON

      final Button submit = (Button) findViewById(R.id.Button03);
      submit.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v)
          {

            //Perform action on click
             Toast.makeText(display.this,"You have selected to submit data of students",Toast.LENGTH_SHORT).show();
             call2();           
          }

      });      

   } //OnCreate method ends

  After that I have my call2 method as follows:

       public String call2()
        {
      String result="";
      HttpParams httpParams = new BasicHttpParams();
      HttpPost httppost = new HttpPost("http://10.0.2.2/enterdata/Service1.asmx");
          HttpClient client = new DefaultHttpClient(httpParams);

       try
     {


     JSONArray jsArray = new JSONArray(items2);
     jsArray.put(items2);   

     int TIMEOUT_MILLISEC = 10000;  //= 10 seconds

     HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
     HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);


     httppost.setEntity(new ByteArrayEntity(
     result.toString().getBytes("UTF8")));
     HttpResponse response = client.execute(httppost);

     if(response.toString()=="success")
     {
     System.out.println(response);

     }


    }

     catch(Exception e)
        {
          e.printStackTrace();

        } 
     return result;

 }

meine web-service-code zurückgibt, die "Erfolg" nach dem einfügen der Datensätze

     public class Service1 : System.Web.Services.WebService
     {

    [WebMethod]
    public String put(String value)
    {
        int count=1;
        int rows;

        SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=student;User ID=sa;Password=123");
        try
        {
            myConnection.Open();
            count++;
            SqlCommand myCommand = new SqlCommand();
            myCommand.Connection = myConnection;
            myCommand.CommandText = "insert into record values('"+ count +"','" + value + "')";
            myCommand.Parameters.Add("@value", SqlDbType.VarChar).Value = value;
            rows = myCommand.ExecuteNonQuery();
            SqlDataReader myReader = myCommand.ExecuteReader();

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        finally
        {
            myConnection.Close();
        }

        return "success";
    }

dies ist die log cat, nachdem ich entfernen Sie die If-Anweisung von meinem Android-code in Methode Ruf 2

   11-10 09:19:28.447: INFO/System.out(412):   org.apache.http.message.BasicHttpResponse@44f5d6b8
   11-10 09:22:39.957: WARN/KeyCharacterMap(440): No keyboard for id 0
   11-10 09:22:39.957: WARN/KeyCharacterMap(440): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
   11-10 09:22:40.447: DEBUG/dalvikvm(124): GC_EXPLICIT freed 1224 objects / 67584 bytes in 363ms
   11-10 09:22:42.498: DEBUG/dalvikvm(440): GC_FOR_MALLOC freed 2924 objects / 197768 bytes in 80ms
   11-10 09:22:42.587: INFO/System.out(440): org.apache.http.message.BasicHttpResponse@44f357a0

Wenn ich jetzt mein code, ich bin nicht in der Lage, um zu sehen, jede Antwort in der logcat. Meine println-Anweisung wird nicht immer ausgeführt, und ich weiß nicht, warum

Kann mir jemand helfen?

  • Sind Sie immer alle Ausnahmen/timeout passiert? Ihre println-Anweisung wird nicht ausgeführt, da die Antwort nicht "Erfolg"
  • Keine sehen dieses logcat : pastie.org/2839910
InformationsquelleAutor Parth Doshi | 2011-11-10
Schreibe einen Kommentar