Can't turn XML response into an simplexml object - simplexml

I asked this question before but I got no answers. I'll try to narrow down the question.
See this post
What's wrong with this code:
$url = "http://.../fogbugz/api.asp?cmd=logon&email=" . $_UN . "&password=" . $_PW;
$resp = new SimpleXMLElement(file_get_contents($url));
Yields:
SimpleXMLElement Object ( [token] => SimpleXMLElement Object ( ) )
If I output the response of file_get_contents directly to the screen using a header I see the response is correct and the token element is filled with a valid token. Yet simplexml doesn't seem to be able to read the token.

I don't think SimpleXML is able to parse CDATA sections and since most of what the FogBugz XML API returns is UTF-8 data, it is put into XML CDATA blocks. Your browser might be hiding that from you, but if you look at the raw info return from cmd=logon, I believe it is a CDATA.

Related

ixudra/curl post multipart/form-data with different content type

I am trying to post multipart/form-data in laravel using ixudra/curl that specify the data is application json. The problem Im facing right know is to assign the type for data and still make the header content type is multipart/form-data.
$contents = storage_path('app/curl.txt');
$dataJson = '{"bId":"79", "docId":"23"}';
$response = Curl::to($url)
->withHeaders( array(
'Authorization: Bearer 123432',
'grant_type: jwt-bearer' ) )
->withData( array ('data' => $dataJson ))
->withFile('file', $contents, 'text/*', 'curl.txt')
->containsFile()
->withResponseHeaders()
->returnResponseObject()
->post();
For the curl, it is like this. Somehow, the error is "Failure to Authenticate OAuth Token" and the header content type is not multipart/form-data
curl -v -H "Authorization:Bearer 123432"
-H "grant_type:jwt-bearer"
-F "file=#\"/jet/app/www/default/test/storage/app/curl.txt\""
-F "data={\"bId\":\"79\", \"docId\":\"23\"};type=application/json"
"https://url/private"
Any idea? thanks for your time.
is this still an issue? Looking at your code, I don't see any errors in there. You don't need to include the containsFile() method in there but that's really a detail that won't effect your result in any way.
Based on your description, I doubt that the file has anything to do with the error. I'd recommend trying to make sure if the authentication is correct by using it on a simple GET request, just to make sure. If that works, you should dig deeper into the form.

How to place comments in Postman?

How to place comments inside Postman? Specifically in the JSON request body section?
I want to comment-out a particular key or value from the request body so that it is not sent.
Commenting out a JSON key/value pair with // or /* ... */ appears as a styled comment inside Postman:
But sending this request results in server errors such as the below, and it's clear that the commented-out line is being sent as part of the request body:
Unexpected character ('/' (code 47)): maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)
at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 2, column: 6
]
The JSON spec does not allow comments: Can comments be used in JSON?
I want Postman to strip the commented lines prior to being sent in the request.
You can write documentation and comments using the description section of the requests, collections or folders.
Finally, since Postman v8.3.0 you can do this in your collections pre-request script:
// Strip JSON Comments
if (pm?.request?.body?.options?.raw?.language === 'json') {
const rawData = pm.request.body.toString();
const strippedData = rawData.replace(
/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g,
(m, g) => g ? "" : m
);
pm.request.body.update(JSON.stringify(JSON.parse(strippedData)));
}
This strips all comments from the json and sets the current body to the cleaned one, there are more examples for other body types (GraphQL, URL Encoded, Form Data) in the original github post this code is based from.
A "Comments" option/button is above the send button for every request.
But still, we can't add a comment in the request body, maybe in future, they'll provide this feature.
I checked with GitHub where Postman has their feature requests and bugs tracked, Link here:
Feature request: Raw body editor JSON comment #3358
https://github.com/postmanlabs/postman-app-support/issues/3358
You can go and add comments there so that this feature would be considered for their next release. Also, I found out that you can copy and paste <!-- comment--> to make a comment.
It has been done by Script
https://community.postman.com/t/request-body-should-be-able-to-be-commented/8288
Pre-request Script create an object, convert it to a string, then expose it
object = {
// product: "{{displayName}}",
price : "15.5"
}
pm.environment.set("object", JSON.stringify(object));
Request Body called the variable object
{{object}}
In Postman v9.13.0 you can do so using block comments
Not the actual question's answer, but this addresses the highly upvoted comment below the question:
I just want to disable some code not want to add comments or descriptions..how can I do that? – Mahender Reddy Yasa
Ignoring the comment validation and sending request is now working for me in latest postman 7.7.3 64 bit version of windows.

reCaptcha invalid json response

Using the recaptcha javascript client ( http://www.google.com/recaptcha/api.js?onload=vcRecaptchaApiLoaded&render=explicit ) the automatic request (GET https://www.google.com/recaptcha/api2/userverify?k=XXXXXXXXX) after you select the correct images returns an invalid json which afterwards is sent to back to google and their json validation fails. This worked as expected for months now. Not anymore :(
Server side library used reCaptcha PHP (1.1)
Response
)]}'
["uvresp","03AHJ_Vuup5SJJ583dSIfezFl80dp2AlJ_rZpz3vqGWlOTmbjZqH8izwjruJASNhQI0tOOnmj2Pzg14xMw7dryeqVfTGhx6dg_x2i0PRA1ZeDyrBNn8DX-w5S262Zb3_ZWKj5JDBiqPVnXtNLGbyBxjd97VHanspJWU_-qKWLSWVKxLK6n3lm9Biw33oUCEiGA39GNa09Z6TSAEtnolQCf_LPPRWKoE_e50f2s5ZpUVG5GNVdX7qGBRwphTgcUhwOjA8uYTzmA9co3Jwk2KR5UQ0zzVRJzRZZTBuK9km3PE1WV05ACAwrJi29niDpVaRmpooAnIkHNgGyGBu7u3W7gU6YAHtwya8PYhdF__G_MMG8XpVFDTBa196hKD6hxw-E2PsxmoIQJrU1K89mmzNIh-xLNQ7KJvrBMzVf8A5FHyUQgL5UNDWVwSkWCdC_3swxBzi7R3p8VIrUtkIqJFA_GSAxy0cBRJ8J55Pfs5rzhfR8j-x1hGCzi_6vJrbrwfNesoLEB7GWJtElcljhBYvcDNzU_B_VJ7Sck-6i1Nd0qdmtSiCRZYNyaZ8uGLoDdNgCY-0Oi4802AlI26H7TjGBcKnr4gmaHXTNRf1W7x_3FV05DxVsTqeAlo8zGqmiVqcgmX64BbLK4fD9Xoait1_Lp5vK26fCaOQmGKF7CJaYPuxnX-zXgSkfZDCG6rs6xv1CfZQnIKD0W3Yz522VD4YdNfATb3FywhFWbZuxoBIt6vslZDlPXh2MYOkAmYfIPIo8WoWazMoLI_8iNBZPiMlRL0PS5aQiLSrvbf-sknMHhfM2MJYsfrQjC52aDRaHYdcZbY6Wxlhw0tQEknX8B47_DAQzCKkpoFsecO1eMHuInIykZ1l7TOdZMytI-NzGg21KeKAE8dK6ZWee0UEqDJvCkj5aH5TQcBA--ygbOS186bAptUP5n6WvORx1Nb2ZU_AF9fB23PJWH1xvB4gZoNDvhLmdpkE1Po9Lyim1P61E2rrgYjWgPRwT4jUo",1,120]
Any ideas?
Thanks
I think it's a duplicate of https://stackoverflow.com/a/36862268/2140017
And here is my answer from that link:
Actually the value returned is not valid json but well parsed by the
Google's API.
Is it a protection ? I don't know, but if you look at the javascript,
you can find that:
var jm=function(a,b,c,d,e,g,h,l,r){this.xl=a;this.$c=c||"GET";this.Ka=d;this.Gg=e||null;this.Td=m(h)?h:1;this.ye=0;this.xh=this.Nh=!1;this.uh=b;this.Mh=g;this.md=l||"";this.Zb=!!r;this.Wf=null};f=jm.prototype;f.getUrl=function(){return this.xl};f.ug=function(){return this.$c};f.Ca=function(){return this.Ka};f.fi=function(){return this.Zb};f.bi=function(){return this.md};var nm=function(){G.call(this);this.nj=new hm(0,mm,1,10,5E3);H(this,this.nj);this.ad=0};x(nm,G);var mm=new Nh;nm.prototype.send=function(a){return new Lc(function(b,c){var d=String(this.ad++);this.nj.send(d,a.Uf.toString(),a.ug(),a.Ca(),mm,void 0,u(function(a,d){var h=d.target;if(Xk(h)){var l=a.ml;h.B?(h=h.B.responseText,0==h.indexOf(")]}'\n")&&(h=h.substring(5)),h=Hg(h)):h=void 0;b(new l(h))}else c(new om(a))},this,a))},this)};var om=function(a){y.call(this);this.request=a};x(om,y);
especially take a look at:
var l=a.ml;h.B?(h=h.B.responseText,0==h.indexOf(")]}'\n")&&(h=h.substring(5)),h=Hg(h)):h=void 0;`
The parser explicitly checks that the value begins by )]} and strips
it.
I suggest you to just apply the same substring on the "json" string

Find what my Query's POST data is?

This is what I am having trouble understanding and doing.
I need to add a header called sign with the query's POST data signed by my key's "secret" according to the HMAC-SHA512 method. What is my query's post data? And how can I find it so that I can encrypt it and send it as a header.
These are my parameters: "command" => "returnBalances", "nonce" => Time.now.to_i
Please let me know:
How do I find my post request data.
How do I use the HMAC-SHA512 method to encrypt this data so that I can send it in a header. (using Ruby)
Thank you people let me know.
I answered your question more completely here, in the context of the Poloniex exchange:
Ruby Http Post Parameters
To answer your specific questions from this post:
How do I find my post request data?
POST data simply means the body of your request. This could be JSON, plain text, form data, etc. In cases where a specific format (i.e. JSON) isn't mentioned, POST data probably refers to POST form data (Content-Type: application/x-www-form-urlencoded). This is how data submitted from a web form is formatted and indeed that appears to be what Poloniex is looking for.
x-www-form-urlencoded data can be produced like this in Ruby:
form_data = URI.encode_www_form({:command => 'returnBalances', :nonce => Time.now.to_i * 1000 })
puts form_data
command=returnBalances&nonce=1447537613000
Mozilla Developer's Network link on POST form data.
How do I use the HMAC-SHA512 method to encrypt this data so that I can send it in a header? (using Ruby)
HMAC digest produces a unique string based on a secret key and the data provided. In Ruby, you can produce an HMAC digest like so:
OpenSSL::HMAC.hexdigest( 'sha512', secret, form_data)

Magento getPost empty array

I have the following code (please excuse the bad coding, it's like that to debug):
$postData = Mage::app()->getRequest()->getPost();
if(!$postData)
{
$postData = $this->getRequest()->getPost();
}
if(!$postData)
{
$postData = $_POST;
}
As you can see, I am simply trying to get the HTTP POST values.
Here's the scenario:
From a HTTP POST Simulator, the data comes through
From the Shopify webhook, nothing comes through (just "Array()")
Shopify posting to PostCatcher shows a lot of data
Shopify is posting in JSON format.
Any ideas as to ahy I can't catch the POST array?
You cant get JSON post values by using simply $_POST or Mage::app()->getRequest()->getPost();. Just try this,
$value = json_decode(file_get_contents('php://input'));
print_r($value);
In one of my project I got the same error
Mage::app()->getRequest()->getPost(); was giving the blank values.
I was using one extension when I was submitting the form there was one description field for the manufacturer.
If it was having text content like from , select or some content similar to SQL commands.
It was not posting the form data.
The reason was the hosting provider had some settings for sanitizing the data to prevent the SQL injection.
I raised the ticket to the hosting provider and the problem was solved.
Before this I tried lot of coding stuff which was not required.
Basically
Mage::app()->getRequest()->getPost(); and $this->getRequest()->getPost(); are the same if you are in a controller.
They are also the same thing with $_POST with some additional filtering on the values.
So if you receive an empty array in any case you should receive an empty array for all cases.
Make sure the data is sent through POST.
Also try to see how $this->getRequest()->getParams() look like. Maybe Magento considers that the parameters are sent through _GET

Categories

Resources