doufang6268 2014-01-11 10:28
浏览 55
已采纳

将ArrayList从Java传递到PHP Web服务

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?

  • 写回答

1条回答 默认 最新

  • duanke2503 2014-01-11 10:33
    关注

    You can use an HTTP client e.g. this one.

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

    and send a GET/POST request to your WebService.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮