簡體   English   中英

使用Java WebService將參數添加到HTTP標頭

[英]add parameter to an http header using java webservice

我有這個HTTP標頭:

    HTTP/1.1 200 OK
    Server: Apache-Coyote/1.1
    Content-Type: application/json;charset=UTF-8
    Transfer-Encoding: chunked
    Date: Tue, 15 Mar 2016 17:08:29 GMT

我想要添加2個參數:mytotalcount和mytotalresult。

我必須將此添加到我的響應中,但是它不起作用,我不能做:

    response.Headers.Add("mytotalcount", "10");

也做不到

    request.setAttribute("mytotalcount","10");

因此,請您阻止任何想法? 謝謝你的幫助 !

這是代碼的一部分:

    public class SitesResponse {
private Result result;
private List<GeographicSite> site;
public SitesResponse () {
    this.result = new Result();
    this.site = new ArrayList<GeographicSite>();
    }
public List<GeographicSite> getSite() {
    return site;
}
public void setSite(List<GeographicSite> site) {
this.site = site;
}

}利用SitesResponse進行課堂教學

    SitesResponse response = new SitesResponse();

    if (testiing) {
    try {response = siteManager.geographicSitesAPIV1(args);
    response.getResult().setCode("error");
    response.getResult().setLabel("no addr found");

這就是我早先嘗試過的

    System.out.println(response.toString().getBytes().toString()+"azezae");
     //   request.Headers.Add("headername", "headervalue");
    //  request.setAttribute("X-Total-Count","10");
    //response.setAttribute("X-Result-Count", "7");
     //response.setIntHeader("mytotalcount", 5); 
     //////////////////////////////////////////////////:::::::

在要添加兩個參數的圖片中, 來自SOAPui

再次您好,謝謝您的時間,我正在嘗試編輯錯誤的課程,所以我剛才所做的只是

    resp.addIntHeader(att, 10);
    resp.addIntHeader(att2, 5);

感謝您的時間和答復!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM