开发者

UnKnownHostException in Http Post of Android Application

In Http Post, the values are not send to server. I got unknownhostexception at following line.HttpResponse rs=httpclient.execute(httppost);

http Coding:

          HttpClient httpclient=new DefaultHttpClient();

          HttpPost httppost=new HttpPost("http://www.mysite.com/fasttrack/androidapps.php");


          httppost.setEntity(new UrlEncodedFormEntity(data));

          appendLog("7)Value Encoded to url successfully");


      HttpResponse rs=httpclient.execute(httppost); // unknownhostexception got

I added <uses-permission android:name="android.permission.INTERNET"/> in Manifestfile also...

Note : this codings works fine before I added log file codings...

my Log File coding is below:

public void appendLog(String text)
        {      
            //File logFile = new File("alog.txt");
           File logFile = new File("sdcard/alog.file");
           if (!logFile.exists())
           {
              try
              {
                 logFile.createNewFile();
              } 
              catch (IOException e)
              {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
              }
           }
           try
           {
              //BufferedWriter for performance, true to set append to file flag开发者_如何学C
              BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)); 
              buf.append(text);
              buf.newLine();
              buf.close();
           }
           catch (IOException e)
           {
              // TODO Auto-generated catch block
              e.printStackTrace();
           }
        }   


Sometimes the android emulator's browser stops working. So, try to restart your emulator from cmd like this,

run->cmd->your_sdk_path->tools->emulator -avd avd_name -dns-server 8.8.8.8
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜