I want to simply send get request through android but it doesn't work my code is as follow,

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

I want to simply send get request through android but it doesn't work my code is as follow,


public void sendGET(String GET_URL) throws IOException
try
URL obj = new URL(GET_URL);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", USER_AGENT);
int responseCode = con.getResponseCode();

catch (IOException e)
e.printStackTrace();




This is method that i had written for get request.
GET_URL is a string in my case its value GET_URL=192.168.4.1?value=1.
I had call this method on button click but it doesn't work in android while in java it work perfect.
Note: my apk compiles without any error and it run also but get request doesn't work.
Button code is as follow,


led1on.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
try
sendGET("http://192.168.4.1/?linker=1");
Toast.makeText(getApplicationContext(),
"Led1 ON Clicked!", Toast.LENGTH_SHORT).show();

catch (IOException e)



);





What is the error you are getting?
– Ashraff Ali Wahab
42 mins ago





@AshraffAliWahab I am getting no Error. The get request doesn't work. This get request is recieved by arduino which in turn ON led. But when i click button it doesn't work. The same code for get request is working in java. I had called it at onClick of button in java it works and led gets ON but it doesn't works in android. All i want to do is how i can use get request in android .
– Sami Ullah
35 mins ago





1 Answer
1



i think this is a funny mistake...



server on which port are listening? you should specify server port in request url like http://192.168.4.1:8080/?linker=1






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

Executable numpy error

Trying to Print Gridster Items to PDF without overlapping contents

Mass disable jenkins jobs