当前位置:web 服务器 > Apache >>

利用ApacheHttpClient的跨工程数据请求

package com.yanxiu.user.action.search.util;

import java.util.HashMap;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.log4j.Logger;

/**
 *  
 * @author zhangtao 2012/2/21
 *  
 */
public class TrainService implements Runnable {

    private static final Logger log = Logger.getLogger(RestService.class);
    private final static String MyTraining_URL = " http://192.168.1.26:8099/dts/sq/sq!myTrainsForSqPersonalCenterLeft.action";
    private final static String MyCourse_URL = " http://192.168.1.26:8099/dts/sq/sq!selcourselist.action";
    private final static String HomeWork_URL = " http://192.168.1.26:8099/dts/sq/sq!homeworklist.action";
    private final static String RRecordAndNotice_URL = " http://192.168.1.26:8099/dts/sq/sq!showRecordNew.action";
    private final static String Complete_URL = " http://192.168.1.26:8099/dts/sq/sq!completetrainlist.action";
    private final static String SelCourse_URL = " http://192.168.1.26:8099/dts/sq/sq!doSelCourseForSq.action";
    private final static String UnselCourse_URL = " http://192.168.1.26:8099/dts/sq/sq!doUnselCourseForSq.action";
    private final static String Teacher_URL = " http://192.168.1.26:8099/dts/sq/sq!getAllMembersAndGroupMsg.action";

    private final static String SaveHomeWork_URL = " http://192.168.1.26:8099/dts/publichomework/publichomework!save_forSq.action";
    private final static String UpdateHomeWork_URL = " http://192.168.1.26:8099/dts/publichomework/publichomework!public_homework_update_forSq.action";
    private final static String PersonUp_URL = " http://192.168.1.26:8099/dts/publichomework/publichomework!commend_person_updateForSq.action";
    private final static String findUpdate_URL = " http://q.yanxiu.com/dts/publichomework/publichomework!public_homework_update_forSq.action";
    private static String userid;
    private static String nickname;
    private static String trainingid;
    private static String coursed;
    private static String publicAssigmentId;
    private static String homeworkid;
    private static String title;
    private static String content;
    private static String message;

    public TrainService(String userid, String nickname, String trainingid,
            String coursed, String publicAssigmentId, String homeworkid,
            String title, String content, String message) {
        super();
        TrainService.userid = userid;
        TrainService.nickname = nickname;
        TrainService.trainingid = trainingid;
        TrainService.coursed = coursed;
        TrainService.publicAssigmentId = publicAssigmentId;
        TrainService.homeworkid = homeworkid;
        TrainService.title = title;
        TrainService.content = content;
        TrainService.message = message;
    }

    public static String TrainServerRequest(HashMap<String, String> params,
            String url) {
        String info = null;
        HttpClient httpclient = new HttpClient();
        PostMethod post = new PostMethod(url);
        post.setRequestHeader("application/json", "charset=UTF-8");
        NameValuePair simcard = new NameValuePair("userid",
                params.get("userid"));
        NameValuePair simcard2 = new NameValuePair("trainingid",
                params.get("trainingid"));
        NameValuePair simcard3 = new NameValuePair("coursed",
                params.get("coursed"));
        NameValuePair simcard4 = new NameValuePair("publicAssigmentId",
                params.get("publicAssigmentId"));
        NameValuePair simcard5 = new NameValuePair("homeworkid",
                params.get("homeworkid"));
        NameValuePair simcard6 = new NameValuePair("title", params.get("title"));
        NameValuePair simcard7 = new NameValuePair("content",
                params.get("content"));
        NameValuePair simcard8 = new NameValuePair("message",
                params.get("message"));
        post.setRequestBody(new NameValuePair[] { simcard, simcard2, simcard3,
                simcard4, simcard5, simcard6, simcard7, simcard8 });
        try {
            httpclient.executeMethod(post);
            int code = post.getStatusCode();
            if (code == 200) {
                info = post.getResponseBodyAsString();
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return info;
    }

    public static String findTrainingRequest(HashMap<String, String> params) {
        String URL = MyTraining_URL;
  

补充:综合编程 , 其他综合 ,
Apache
IIS
Nginx
Tomcat
如果你遇到web 服务器难题:
访问www.zzzyk.com 试试
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,