Joke Collection Website - Public benefit messages - Java language uses post to call webService.

Java language uses post to call webService.

WebService can have Get,? Called in four ways: Post, Soap and Document. The following Java calls the WebService code through post:

Import? Java . io . buffered reader;

Import? Java . io . io exception;

Import? Java . io . inputstream;

Import? Java . io . inputstreamreader;

Import? Java . io . output stream;

Import? Java . io . output streamwriter;

Import? Java . net . URL;

Import? Java . net . URL connection;

Import? Java . net . URL encoder;

Import? org . Apache . cxf . endpoint . client;

Import? org . Apache . cxf . jaxws . endpoint . dynamic . jaxwsdynamicclientfactory;

/**

*? Function description: WebService call

*?

*/

Public? Class? ClientTest? {

/**

*? Function description: HTTP-POST

*?

*/

Public? String? post()? {

OutputStreamWriter? Out? =? null

StringBuilder? sTotalString? =? New? StringBuilder();

Try it? {

Website? urlTemp? =? New? Website (

"/web services/weather web service . asmx/getSupportCity ");

URLConnection? Contact? =? URL temp . open connection();

connection . setdoooutput(true);

Out? =? New? output streamwriter(connection . get output stream(),? “UTF-8”);

StringBuffer? sb? =? New? string buffer();

Sb.append("byProvinceName= Fujian ");

out . write(sb . tostring());

out . flush();

String? sCurrentLine

sCurrentLine? =? "";

InputStream? l _ urlStream

l_urlStream? =? connection . getinputstream(); //? request

BufferedReader? l_reader? =? New? BufferedReader (new? Input stream reader (

l _ urlStream));

What time? ((sCurrentLine? =? l_reader.readLine())? ! =? null)? {

stotalstring . append(sCurrentLine);

}

}? Catch? (exception? e)? {

e . printstacktrace();

}? Finally? {

What if? (null? ! =? Out)? {

Try it? {

out . close();

}? Catch? (IOException? e)? {

e . printstacktrace();

}

}

}

Return? stotalstring . tostring();

}

}