2 Replies - 1626 Views - Last Post: 09 September 2012 - 08:48 PM

#1 kabuto178  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 130
  • Joined: 29-January 11

problem with httprequest

Posted 05 September 2012 - 10:47 AM

The internet permission is already set, and the emulator gets internet access. No data is being printed in the textview i requested it to be, not sure if the http works but just wrong method format or the http request does not at all
First file main activity which gets the class data from the second
public class SecondActivity extends Activity  {
	
	TextView data_details;
	/*HttpPost httppost;
    StringBuffer buffer;
    HttpResponse response;
    HttpClient httpclient;
    InputStream inputStream;
    SharedPreferences app_preferences ;
    List<NameValuePair> nameValuePairs;
    String name="nove",pass="jerome";*/
    Button clicker;
    
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        
       data_details = (TextView)findViewById(R.id.http_data_details);
       clicker = (Button)findViewById(R.id.button1);
       
      // new loadStuff().execute();
      
	
       
       
       clicker.setonclickListener(new View.onclickListener(){
    	   public void onclick(View v)
           {
    		   
    		 /*CALLS THE CONNECTIONS CLASS
               Intent connections = new Intent(SecondActivity.this,DisplayActivity.class);
               startActivity(connections);*/
    		   
    		   loadStuff test = new loadStuff();
    	       String returned;
    		   try {
				returned = test.getData();
				data_details.setText(returned);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
    		   
           }
       }); 
      
    }

    
		
		
	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_second, menu);
        return true;
    }
}


package com.example.tester;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.content.SharedPreferences;

public class loadStuff {
	HttpGet httppost;
    StringBuffer buffer;
    HttpResponse response;
    HttpClient httpclient;
    InputStream inputStream;
    SharedPreferences app_preferences ;
    List<NameValuePair> nameValuePairs;
    String name="nove",pass="jerome";
    
		public String getData() throws Exception{			
			BufferedReader in = null;
		    String data = null;
		    
			try {
					        
   			  /*  ConnectivityManager cm = (ConnectivityManager) 
   			    getSystemService(Context.CONNECTIVITY_SERVICE);
   			    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
   			    // if no network is available networkInfo will be null
   			    // otherwise check if we are connected
   			    if (networkInfo != null && networkInfo.isConnected()) {
   			    	
   			    }*/			   	
			    
				httpclient = new DefaultHttpClient();
			    httppost = new HttpGet();
			    /* Add your data
			    nameValuePairs = new ArrayList<NameValuePair>(2);
			    nameValuePairs.add(new BasicNameValuePair("UserEmail", name));
			    nameValuePairs.add(new BasicNameValuePair("Password", pass));
			    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));*/
			    URI website = new URI("http://www.mybingback.com");
			    httppost.setURI(website);
			    
			    // Execute HTTP Post Request
			    response = httpclient.execute(httppost);
			    inputStream = response.getEntity().getContent();	    
		            
			    in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
			    StringBuffer sb = new StringBuffer();
			    String line = "";
			    String new_line = System.getProperty("line.separator");
			    
			    while((line = in.readLine()) != null){
			    	sb.append(line + new_line);
			    }
			    in.close();
			    data = sb.toString();
			    
			    return data;  
			    
				}finally{
						if(in != null)
								try{
									in.close();
									return data;
								}catch(Exception e){
									e.printStackTrace();
								}
					
						}
			
			      
			    }
			
		}//END OF LOADSTUFF




Is This A Good Question/Topic? 0
  • +

Replies To: problem with httprequest

#2 kabuto178  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 130
  • Joined: 29-January 11

Re: problem with httprequest

Posted 07 September 2012 - 05:17 AM

Update: got it to send the data to the php and then it updates the db after, but does not return anything to the httppost to display in the textview, and crashes shortly after running
Was This Post Helpful? 0
  • +
  • -

#3 kabuto178  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 130
  • Joined: 29-January 11

Re: problem with httprequest

Posted 09 September 2012 - 08:48 PM

Solved after much reviewing, ended up restructuring the code
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1