0
import dispatch._
val h = new Http
val req = url(url).as_!(username, password)
val handler = req << (payload, "application/xml") >:> identity
handler.apply { 
    case (200, _, Some(entity), _) => (200, Some(entity))
    case (status, _,_,_) => (status, None)
}
val response = h(handler)

私はこれを試しました:

public static void postService(Profile user, String subject, String body){
    Credentials credentials = new UsernamePasswordCredentials(userName, authToken);
    AuthScope authScope = new AuthScope(baseUrl, 80, AuthScope.ANY_REALM);
    HttpClient client = new HttpClient();
    PostMethod post = new PostMethod(baseUrl);

    client.getParams().setAuthenticationPreemptive(true);
    client.getState().setCredentials(authScope, credentials);

    String payload = makePayload(user, subject, body);
    RequestEntity entity = null;
    try{
        entity = new StringRequestEntity(payload, CONTENT_TYPE, null);
    } catch(UnsupportedEncodingException e){
        e.printStackTrace();
    }
    post.setRequestEntity(entity);

    try{
        client.executeMethod(post);
    } catch(IOException e){
        e.printStackTrace();
    } catch(HTTPException e){
        e.printStackTrace();
    }
}

更新 - 解決済み:これは AuthScope の誤解でした。基本的に、「mysite.com」だけでなく「https://mysite.com」というプロトコル付きのURL全体を渡していたことがわかったので、この問題を解決しました。

4

1 に答える 1

0

これは AuthScope の誤解でした。基本的に、「mysite.com」だけでなく「https://mysite.com」というプロトコル付きのURL全体を渡していたことがわかったので、この問題を解決しました。

于 2013-01-11T09:36:47.080 に答える