简体   繁体   中英

Passing ArrayList from Java to PHP webservice

I have a java program that contains a username and passwords (strings) and an ArrayList of objects with 4 attributes (long, int, int int) and I want to pass these 3 things to a WebService (that I have yet to make). My host is Bluehost and it's a shared server so I won't have Java available server side it will need to be in PHP.

What is the best way of connecting to the webservice and passing this into php?

EDIT.

OK so I now have something like this:

public void upload(ArrayList<MyObject> myList) throws Exception{

    //HTTP POST Service
    try{
        HttpClient httpclient = HttpClientBuilder.create().build();
        URI uri = new URIBuilder()
        .setScheme("http")
        .setHost("www.myHost.com")
        .setPath("/myWebservice.php")
        .setUserInfo(userID, password)
        .build();
        HttpPost httppost = new HttpPost(uri);
        httpclient.execute(httppost);
    }catch (Exception e) {
        e.printStackTrace();
    }
}

But I'm still not sure how I can pass the ArrayList in a way that I'll be able to receive and split it into it's components on the PHP side?

You can use an HTTP client eg this one.

http://hc.apache.org/httpcomponents-client-ga/tutorial/html/index.html

and send a GET/POST request to your WebService.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM