Commit 7ba879ad by Patryk Czarnik

Pierwszy program kliencki REST

parent 203a48ee
package sklep.klient;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;
public class PrzykladoweZapytanie {
// To pisaliśmy na żywo w tracie zajęć.
public static void main(String[] args) {
System.out.println("Buduję klienta");
Client client = ClientBuilder.newClient();
System.out.println("Wysyłam zapytanie...");
Response response = client.target("http://localhost:8080/PC34-RestSerwer-1.0/products.json/1")
.request().buildGet().invoke();
System.out.println("Mam odpowiedź: " + response);
System.out.println("Kod: " + response.getStatus());
System.out.println("Content-type: " + response.getMediaType());
String trescOdpowiedzi = response.readEntity(String.class);
System.out.println("Treść odpowiedzi:");
System.out.println(trescOdpowiedzi);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment