Waiting for a wait service 2 json objects

I have a service that expects 2 objects ... Authentication and Client. Both are displayed correctly.

I am trying to use them as Json, but it is difficult for me to do this. If I specify only one parameter, it works fine, but how can I call this service passing two parameters? Always give me some kind of exception.

Here is my rest service:

@POST
@Path("login")
@Consumes("application/json")
public void login(Authentication auth, Client c)
{
    // doing something
}

And here is my PHP consumer:

$post[] = $authentication->toJson();
$post[] = $client->toJson();

$resp = curl_post("http://localhost:8080/login", array(),
            array(CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
                  CURLOPT_POSTFIELDS => $post));

I tried some variants of what needs to be imposed on CURLOPT_POSTFIELDS, but could not make it work.

+3
source share
1 answer

, , , , , $post , , , , . , , :

Array(
     1 => Array(
          'authentication' => 'some data here'
     ),
     2 => Array(
          'client' => 'some more data here'
     )
)

$post var :

Array(
     'authentication' => 'some data here',
     'client' => 'some more data here'
)

- ( , ):

$authentication = $authentication->toJson();
$client = $client->toJson();
$post = array_merge($authentication, $client);

$resp = curl_post("http://localhost:8080/login", array(),
        array(CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
              CURLOPT_POSTFIELDS => $post));
0

Source: https://habr.com/ru/post/1778503/


All Articles