0

i have problem with two parameters passing with URL link. Can anyone help me?

private void FillDetails(String _userid,int _sporttype) {
    al_TeamName=new ArrayList<String>();

    try{
        spf=SAXParserFactory.newInstance();
        sp=spf.newSAXParser();
        xr=sp.getXMLReader();
        URL sourceUrl = new URL(
        "http://10.0.2.2:2291/acd.asmx/Get_Teams?_userid ="+_userid & "_sporttype="+ _sporttype);
        MyHandler mh=new MyHandler();
        xr.setContentHandler(mh);

        xr.parse(new InputSource(sourceUrl.openStream()));
        setListAdapter(new MyAdapter());


    }
    catch(Exception ex)
    {

    }
}

when i using this code, i am getting null.If i send single parameter then it works fine. Is this correct procedure for URL passing two parameters?

Thanks in advance..........

4 Answers 4

3

UPDATED ANSWER:

Now you have multiple errors in your URL:

URL sourceUrl = new URL("http://10.0.2.2:2291/acd.asmx/Get_Teams?_userid =" + 
    _userid & "_sporttype="+ _sporttype); 
  1. You still have a space before the first = sign
  2. There's no + between the _userid variable and the rest of the string.
  3. The & sign is outside the second string

It should be something like this:

URL sourceUrl = new URL("http://10.0.2.2:2291/acd.asmx/Get_Teams?_userid=" 
    + _userid + "&_sporttype=" + _sporttype);

ORIGINAL ANSWER:

You currently have a space instead of a = sign after your first parameter:

?_userid "+_userid

should be

?_userid="+_userid
Sign up to request clarification or add additional context in comments.

1 Comment

Can you verify that the value that you pass to the method as String _userid isn't null?
1

Solved.

URL sourceUrl = new URL("http://0.0.0.0/acd.asmx/GetList?Value1="+Value1+"&ID="+ID);

Comments

0
"http://10.0.2.2:2291/acd.asmx/Get_Teams?_userid ="+_userid & "_sporttype="+ _sporttype);

You have an & after _userid, which probably does who knows what on _userid. Usually a single & does binary manipulation, so you might be transforming what comes out of _userid. Also, I would recommend URLEncoding your REST tags if you aren't doing that already

I would recommend logging the REST parameters while in development as well to double-check that it's being formed correctly

Update: The & was outside the quote and you needed to use a +

 "http://10.0.2.2:2291/acd.asmx/Get_Teams?_userid ="+_userid + "&_sporttype="+ _sporttype);

2 Comments

That actually is one of the correct formats for binary manipulations. However, that applies an "AND" operation to the 1s and 0s to your string. So, it's taking _userid and comparing its 1s and 0s with "_sporttype". Are you thinking of string manipulation?
There's a few ways to manipulate binary, including addition and subtraction. Usually you do the addition to combine two sets of binary data that has been masked out. You can also use bit shifting >> and << to move bits around. A simple one is extracting a color from a 32-bit integer.
0

If you came here because you searched for a version working in Kotlin (like me), you can use this function to build your URL:

import java.net.URL

// Your URL you want to append the query on
val url: String = "http://10.0.2.2:2291/acd.asmx/Get_Teams"

// The parameters you want to pass
val params: Map<String, String> = mapOf(
        "_userid"      to _user_id
        , "_sporttype" to _sporttype
)

// The final build url. Standard encoding for URL is already utf-8
val final_url: URL = URL(
        "$url?" // Don't forget the question-mark!
        + params.map {
            "${it.key}=${it.value}"
        }.joinToString("&")
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.