updateMyvCardTemp in xmppframework - xmppframework

i try to update myvcard,but always receive a error message ,
《error code="400" type="modify"》 《bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/》《/error》
my code :
XMPPvCardTemp *mycard=[self.appdel.xmppHelper getmyvcard];
NSLog(#"nickname:%#",mycard.nickname);
NSLog(#"name:%#",mycard.name);
NSLog(#"location:%#",mycard.location);
NSLog(#"jid:%#",mycard.jid);
NSLog(#"title:%#",mycard.title);
mycard.title=#"lkasjdfl";
mycard.nickname=#"jdjdjdjd";
mycard.jid=[XMPPJID jidWithString:#"test#im.xujialiang.net"];
[self.appdel.xmppHelper updateVCard:mycard];

Related

Robot Framework bypass HTTPError: 400 Client Error: Bad Request

I have a request which tend to upload a file, if a file with the same name already exists it throws a message that the file already exists. This can be considered as expected result and even though the error I would the test to pass as it is.
This is the code I am using:
Create Session mysession ${test_env}
&{headers} Create Dictionary Content-Type=application/json; charset=utf-8 Authorization=${token}
${json}= Catenate { "FileName": "File.txt", "Content": "PD94bWwg..", "UserId": "email.com" }
${value} Set Variable 2
${value} Convert To Integer ${value}
${json}= Evaluate json.loads('''${json}''') json
#Set To Dictionary ${json["FileName"]}
${json}= Evaluate json.dumps(${json}) json
${resp} POST url=${test_env}/api/nt data=${json} headers=${headers}
${log}= Log To Console ${resp.status_code} 400
Log To Console ${resp.content}
Status Should Be expected_status=any
The test stops at the POST request and does not want to read the expected_status=any and consider the test as pass.
I would appreciate any hints on how to make it pass.
Below code will verify the 400 error and will continue further execution
Run Keyword And Expect Error HTTPError: 400* POST url=${test_env}/api/nt data=${json} headers=${headers}

Is possible to get the full json text that is sent to MSXML2.XMLHTTP?

I'm working in VFP9 sending data (in json format) to an api restfull using MSXML2.XMLHTTP.
I need to know if is possible to get the full json text that is sent. At this moment I only can get the data who is send with the "send" method. I need to see the complete json text, with the headers, data, etc. Is this possible?
Thanks in advance.
Alejandro
I use Microsoft.XMLHttp for REST API calls and works fine for me. Don't know if there would be any difference with MSXML2.XMLHTTP though.
First, here is a REST API test code (testing on typeicode.com):
clear
Local loXmlHttp As "Microsoft.XMLHTTP", lcUrl, postData,userID,id,title,body
*** We want to make this REST API call to typicode.com online test service:
***
*** https://jsonplaceholder.typicode.com/posts
*** with parameters payload
***
*** userId:12
*** title:From VFP
*** body:This is posted from VFP as a test
***
*** We do a POST call and want to 'create' a resource (insert call)
userID=12
title="From VFP"
body = "This is posted from VFP as a test"
Text to postData textmerge noshow
{
"userId":<< m.userID >>,
"title":"<< m.title >>",
"body": "<< m.body >>"
}
endtext
lcUrl = 'https://jsonplaceholder.typicode.com'
loXmlHttp = Newobject( "Microsoft.XMLHTTP" )
loXmlHttp.Open( "POST" , m.lcUrl + '/posts', .F. )
loXmlHttp.setRequestHeader("Content-Type","application/json; charset=UTF-8")
loXmlHttp.Send( m.postData )
*** Print the URL we are sending our POST REST request
? m.lcUrl + '/posts'
? "==================================="
? "Post Test", loXmlHttp.Status
? loXmlHttp.responsetext
? "==================================="
*** We get the response code back with loXmlHttp.Status
*** Since we made a POST call to create a resource, on succesful call
*** we expect an 201-Created code back
*** We also print out the full JSON response from the call
*** Which looks like:
***
*** {
*** "userId": 12,
*** "title": "From VFP",
*** "body": "This is posted from VFP as a test",
*** "id": 101
*** }
***
*** Next line simply has a MessageBox to allow you to see the results
*** of the above call before continuing. It also reminds,
*** 200 is the OK and 201 is the Created response code.
MessageBox("Continue? API Codes: 200-OK, 201-Created",0,"REST API Test",10000)
*** Then we try a new call to REST API with a GET call
*** asking to GET the post with id=3
*** If you have checked the typicode.com page there are some data there for testing:
***
***
*** /posts 100 posts
*** /comments 500 comments
*** /albums 100 albums
*** /photos 5000 photos
*** /todos 200 todos
*** /users 10 users
***
*** In our first call we ask for /posts/3
*** You could also go to this link in your browser to get the response back:
*** https://jsonplaceholder.typicode.com/posts/3
***
clear
m.id = 3
loXmlHttp.Open( "GET" , Textmerge('<< m.lcUrl >>/posts/<< m.id >>'), .F. )
loXmlHttp.Send( )
? "Get post with ID X test", loXmlHttp.Status
? loXmlHttp.responsetext
? "==================================="
*** Again we have a MessageBox to allow you to see the results
*** of the above call before continuing.
MessageBox("Continue? API Codes: 200-OK, 201-Created",0,"REST API Test",10000)
clear
*** Finally we try another GET call to REST API
*** asking to GET the comments done for the id=3
***
*** You could also go to this link in your browser to get the response back:
*** https://jsonplaceholder.typicode.com/posts/3/comments
***
loXmlHttp.Open( "GET" , Textmerge('<< m.lcUrl >>/posts/<< m.id >>/comments'), .F. )
loXmlHttp.Send( )
? "Get test post X comments", loXmlHttp.Status
? loXmlHttp.responsetext
? "==================================="
MessageBox("Continue? API Codes: 200-OK, 201-Created",0,"REST API Test",10000)
clear
*** Let's add another final request in this sample
*** to GET, posts done by the user whose userId is 2
userId = 2
loXmlHttp = Newobject( "Microsoft.XMLHTTP" )
loXmlHttp.Open( "GET" , m.lcUrl + '/posts?userId=2', .F. )
loXmlHttp.Open( "GET" , Textmerge('<< m.lcUrl >>/posts?userId=<< m.userId >>'), .F. )
loXmlHttp.Send( )
? "==================================="
? "GET posts of user X's Test", loXmlHttp.Status
? loXmlHttp.responsetext
? "==================================="
To check what you are really sending, you can use tools like postman or ngrok. I will use ngrok here as it is simple. You can use it for free. Download and then at command prompt:
ngrok http 80
80 is default http port, you might choose say 8080, too. It would start a tunnel and on screen sho you the address, and also a web interface address, likely:
http://127.0.0.1:4040
In your browser, go to that adress. In VFP, change your URL for testing and run. ie: We would test the first call in the above sample like this (the address would be different for you, grab it from ngrok's web interface that you opened in browser):
clear
Local loXmlHttp As "Microsoft.XMLHTTP", lcUrl, postData,userID,id,title,body
userID=12
title="From VFP"
body = "This is posted from VFP as a test"
Text to postData textmerge noshow
{
"userId":<< m.userID >>,
"title":"<< m.title >>",
"body": "<< m.body >>"
}
endtext
lcUrl = 'http://30dd0443adff.eu.ngrok.io'
loXmlHttp = Newobject( "Microsoft.XMLHTTP" )
loXmlHttp.Open( "POST" , m.lcUrl + '/posts', .F. )
loXmlHttp.setRequestHeader("Content-Type","application/json; charset=UTF-8")
loXmlHttp.Send( m.postData )
and run it. In ngrok web interface you would see the POST request done. Clicking it you would see details on right, summary, headers, RAW, ... tabs.
If you downloaded and use Postman (it is really great for working on REST API), you could create a POST request there and send, check response, get code in various languages etc but explaining it here is not as easy as the above ngrok. You should however check it if you would work with REST API and it takes 5 mins to start understanding making requests there.

Requests for Instagram Access token

I am working on Instagram API in Django(python)
I am getting code from
'https://api.instagram.com/oauth/authorize/?client_id=%s&response_type=code&redirect_uri=%s' % (INSTAGRAM_APP_CONSUMER_KEY, redirect_uri)
but when i am exchanging code for access token code is failing
# All arguments are valid
def execute(self, code, redirect_uri, app_id, app_secret):
exchange_url = 'https://api.instagram.com/oauth/access_token'
try:
#Update : get request to post
r = requests.post(exchange_url, params={
'client_id': app_id,
'redirect_uri': redirect_uri,
'client_secret': app_secret,
'code': code,
'grant_type': 'authorization_code'
})
#print(r)
#print(json.loads(r))
print(r.json())
return r.json()
except Exception as e:
print(e)
r.json() gives simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1
Update 1 : r.json() works after request changed from get to post but error
message comming 'You must provide a client_id'
Please let me know what i am doing wrong
I think it requires data in post data, not in query params.
Try this :
your_post_data = {'client_id': '', ... }
r = requests.post('your_url', data=your_post_data)
Ref: Python Requests Docs

Visualworks Cincom Smalltalk SUnit Test case for error condition

I have this piece of code.
|temp|
temp := 5
(temp < 3) ifFalse:[
self error: 'Invalid input'.
].
What will a SUnit test case look like, if I have to test that the above error is raised when I run this code?
Currently when I run the above code, it says "Unhandled exception: Invalid input"
How can I handle this exception?
Try this:
testError
|temp|
temp := 5.
self
should: [(temp < 3) ifFalse:[
self error: 'Invalid input']]
raise: Error

Tumblr Oauth returning 401 on API v2

I'm trying to set up an automatic tumblr post every time I add something new to my website. I'm using the following code:
$conskey = "APIKEY";
$conssec = "APISECRET";
$tumblr_blog = "blogname.tumblr.com";
$to_be_posted = "This is the text to be posted";
$oauth = new OAuth($conskey,$conssec);
$oauth->fetch("http://api.tumblr.com/v2/blog/".$tumblr_blog."/post", array('type'=>'text', 'body'=>$to_be_posted), OAUTH_HTTP_METHOD_POST);
$result = json_decode($oauth->getLastResponse());
if($result->meta->status == 200){
echo 'Success!';
}
As far as I can tell this is all formatted correctly. However this is the first time I've tried to connect up to a JSON API using Oauth so I'm not totally confident in what I'm doing.
This is the exact error I'm receiving:
Fatal error: Uncaught exception 'OAuthException' with message 'Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)' in /home/public_html/edge/tumblr.php:35 Stack trace: #0 /home/public_html/edge/tumblr.php(35): OAuth->fetch('http://api.tumb...', Array, 'POST') #1 /home/public_html/edge/index.php(95): include('/home/...') #2 {main} thrown in /home/public_html/edge/tumblr.php on line 35
Line 35 is the line beginning with $oauth->fetch.
Thanks for any help :-)
EDIT
I've solved the issue by substituting my previous code with the example on this page