i create this to get soap response this is my code
$requestParams = array(
'userName'=>'*********',
'password'=>'*******',
'customerReferenceNo' =>'100014246' ,
'CostCenterCode'=>'100014246',
'consigneeName'=>'Muhammad yousuf',
);enter code here
$client = new SoapClient('http://202.61.51.93:6265?WSDL');
$response = $client->InsertData($requestParams);
$getDetail =$response->InsertDataResult;
print_r($response);
but it show invalid service code in response what will be the issue??
Related
I am using SignatureV4 aws authentication to authenticate my API call,
I am also using Guzzle/Client to call API.
By following these above, my API call works for GET method only and not working for POST method. For POST method call it show an error ( The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method )
My code :
use Aws\Credentials\CredentialProvider;
use Aws\Signature\SignatureV4;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
$request = new Request(
'POST',
'https://XXXXXXXXXXXXx.com/XXXXXx/XXXXXXx',
[
'body' => '{
"param1": "loream",
"param2": "4970",
"param3": "1",
"param4": "2.0",
"param5": "mL",
"param6": "kgs",
"param7": 0,
}'
]
);
$key['credentials'] = array(
'key' => 'XXXXXXXXXXXXXXX-access-key',
'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX-secret-key'
);
$credentials = call_user_func(CredentialProvider::defaultProvider(
$key
));
// Construct a request signer
$signer = new SignatureV4('execute-api',
'us-east-1'
);
// Sign the request
$request = $signer->signRequest($request, $credentials);
// Send the request
try {
$response = (new Client)->send($request);
print_r($response);
}
catch (Exception $exception) {
$responseBody = $exception->getResponse()->getBody(true);
echo $responseBody;
}
$response = (new Client)->send($request);
$results = json_decode($response->getBody());
First of all, I looked at this question and tried the solution, did not work for me.
I am working in Zend 1.12 on a PHP 7.0.22 server.
I have a function that should post data to an API and receive a confirmation of the post.
Whenever I test it in my rest client, in firefox, I get this response from the API call:
"{\"code\":400,\"text\":\"Missing required parameters.\"}".
When I add a header: Content-Type: application/x-www-form-urlencoded I get the expected respone: '200, true'. But even when trying to set this header in my code explicitly, it still always returns 400.
Controller:
$params = array();
$params[ 'name' ] = 'John';
$params[ 'email' ] = 'john#example.com';
$client = new Zend_Http_Client();
$client->setUri( 'path/to/my/api' );
$client->setParameterPost( $params );
$response = client->request( Zend_Http_Client::POST );
var_dump( $response );
I have tried to work with raw data aswell..
$params = array();
$params[ 'name' ] = 'John';
$params[ 'email' ] = 'john#example.com';
$params = json_encode( $params );
$client = new Zend_Http_Client();
$client->setUri( 'path/to/my/api' );
$client->setRawData( $params, 'application/json' );
$response = client->request( Zend_Http_Client::POST );
var_dump( json_decode( $response ) );
When I try to dump the $request with the post parameters inside my API (becuase I wrote the API myself), I see that this is null. Like there is no $post being sent or no data is actually being passed. Because the error 'missing required parameter' is untrue, all the parameters are set ( but maybe not passed / sent correctly ).
Can somebody tell me what I am missing? I have been at this all day.
Thanks!
EDIT (#shevron):
The API expects the parameters to be passed via url-encoded-form. Setting the appropriate header in the REST Client Content-Type: application/x-www-form-urlencoded makes the API return a good response. When this header is not added, I get the error.
I have a custom error templates in my projects for 404, 403 and other exceptions. I want to create unit test case to assert http errors. When I am logging with user and accessing authorized page of Vendor I am getting 403 Access denied in browser but in Unit test case I am always getting 404 page not found error.
Here is my test scenario:
class ErrorExceptionTest extends WebTestCase
{
public function testAccessDeniedException()
{
$server['HTTP_HOST'] = 'http://www.test.com/';
$client = static::createClient(array('debug' => false), $server);
$client->disableReboot();
$session = $client->getContainer()->get('session');
$firewall = 'main';
$token = new UsernamePasswordToken('user', null, $firewall, array('ROLE_USER'));
$session->set("_security_$firewall", serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$client->getCookieJar()->set($cookie);
$client->request('GET', '/vendor/profile/edit');
$this->assertEquals(403, $client->getResponse()->getStatusCode());
$this->assertContains('Sorry! Access Denied', $client->getResponse()->getContent());
}
}
My test case is being failed, when I print response content it will show 404 error template.
Worked around it and find the issue. So, my solution is no need to use http host.
public function testAccessDeniedException()
{
$client = static::createClient(array('debug' => false));
$session = $client->getContainer()->get('session');
$firewall = 'main';
$token = new UsernamePasswordToken('user', null, $firewall, array('ROLE_USER'));
$session->set("_security_$firewall", serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$client->getCookieJar()->set($cookie);
$client->request('GET', 'fr/vendor/profile/edit');
$this->assertEquals(403, $client->getResponse()->getStatusCode());
$this->assertContains('Sorry! Access Denied', $client->getResponse()->getContent());
}
Actually, I have a CakePHP application that authenticates with SimpleSAML using WSO2 Identity Server (it redirects to WSO2IS login page). I need to create a page in my application and send the informations to WSO2IS to authenticate the user. How can I do it? I didn't found any example/documentation about it.
I followed this tutorial.
Files in simplesaml:
config/authsources.php
<?php
$config = array(
'wso2-sp' => array(
'saml:SP',
'entityID' => 'IntranetSP', // I supposed that it is the ID of my Service Provider
'idp' => 'https://soa.rw1.local:9443/samlsso'
)
);
?>
metadata/saml20-idp-remote.php
<?php
$metadata['https://soa.rw1.local:9443/samlsso'] = array(
'name' => array(
'en' => 'WSO2 IS',
'no' => 'WSO2 IS',
),
'description' => 'Login with WSO2 IS SAML2 IdP.',
'SingleSignOnService' => 'https://soa.rw1.local:9443/samlsso',
'SingleLogoutService' => 'https://soa.rw1.local:9443/samlsso',
'certFingerprint' => '6bf8e136eb36d4a56ea05c7ae4b9a45b63bf975d'
);
?>
In my Wso2 IS:
Service provider Configuration:
Service Provider Name: IntranetSP
Local & Outbound Authentication Configuration/Request Path Authentication Configuration: basic-auth
In your service provider configuration, under local and outbound authentication configuration, configure SP to use request path authentication.For more information about doing this, please follow this.
Following is a java code where you can send the request from a client.
#Test(alwaysRun = true, description = "Test login success")
public void testLoginSuccess() throws Exception {
HttpPost request = new HttpPost(TRAVELOCITY_SAMPLE_APP_URL + "/samlsso?SAML2.HTTPBinding=HTTP-POST");
List<NameValuePair> urlParameters = new ArrayList<>();
urlParameters.add(new BasicNameValuePair("username", adminUsername));
urlParameters.add(new BasicNameValuePair("password", adminPassword));
request.setEntity(new UrlEncodedFormEntity(urlParameters));
HttpResponse response = client.execute(request);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line;
String samlRequest = "";
String secToken = "";
while ((line = rd.readLine()) != null) {
if (line.contains("name='SAMLRequest'")) {
String[] tokens = line.split("'");
samlRequest = tokens[5];
}
if (line.contains("name='sectoken'")) {
String[] tokens = line.split("'");
secToken = tokens[5];
}
}
EntityUtils.consume(response.getEntity());
request = new HttpPost(isURL + "samlsso");
urlParameters = new ArrayList<>();
urlParameters.add(new BasicNameValuePair("sectoken", secToken));
urlParameters.add(new BasicNameValuePair("SAMLRequest", samlRequest));
request.setEntity(new UrlEncodedFormEntity(urlParameters));
response = client.execute(request);
String samlResponse = "";
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
while ((line = rd.readLine()) != null) {
if (line.contains("name='SAMLResponse'")) {
String[] tokens = line.split("'");
samlResponse = tokens[5];
}
}
Base64 base64Decoder = new Base64();
samlResponse = new String(base64Decoder.decode(samlResponse))
EntityUtils.consume(response.getEntity());
}
You should be able to achieve this in PHP by sending the same requests.
But if your requirement is to change the login page, you can customize wso2 IS login page as mentioned here without using your own page. If your requirement is this, I recommend you to do this as this will make your life much easier.
I'm trying to connect to the box-api to read the files of my user in my folder. I've created the folder and uploaded the files, then i went to the OAuth2 interface to obtain an API Key. It has given the api key to me so i pasted it in the code:
public function indexAction()
{
try {
$uri = "https://api.box.com/2.0/folders/0/items?limit=100&offset=0";
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'curloptions' => array(CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPHEADER=>array("Authorization: Bearer MYKEY"),
CURLOPT_SSL_VERIFYPEER, false,
CURLOPT_USERPWD, "user:password"),
);
$client = new Zend_Http_Client($uri, $config);
$response = $client->request();
$text= $response->getBody();
} catch (Zend_Exception $e) {
echo "Message: " . $e->getMessage() . "\n";
// Other code to recover from the error
}
}
Following this tutorial on youtube.
The error i'm getting is the following:
Message: Error in cURL request: unable to use client certificate (no key found or wrong pass phrase?)
I registered the application with the name "test". What have I done wrong? What am I missing?
You might try passing the request without the CURLOPT_SSL_VERIFYPEER and CURLOPT_USERPWD options. I don't think those are strictly necessary -- to my knowledge Box doesn't do any client certificate validation -- and they may be causing the problem.
The use of Zend http client by itself is better than using the curl adapter.Besides the username and password are not required to authenticate. You can perform the operation only after you have received th access token from the authorization procedure of Oauth2 of Box-API. The zend http client call that can be used is the following:
$client = new Zend_Http_Client('https://api.box.com/2.0/folders/0');
$client->setMethod(Zend_Http_Client::GET);
$client->setHeaders('Authorization: Bearer '.$access_token);
$response = $client->request()->getBody();
My 2 cents.