Rest API Authentication with Autohotkey
i want to POST a string with Autohotkey to a Rest API.
On another question i found something like this:
URL := "http://localhost:8000/createPlayer"
HttpObj := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HttpObj.Open("POST", URL, 0)
HttpObj.SetRequestHeader("Content-Type", "application/json")
json_str := ({"name": "Any Name"})
Body = json_str
HttpObj.Send(Body)
MsgBox, %Body%
Result := HttpObj.ResponseText
Status := HttpObj.Status
msgbox % "status: " status "`n`nresult: " result
so here is my Question: where do i put the authentication-information? I read, that i have tho give the string username:password coded as Base64 to the API, but where? Thank u very much.
The Example in the documentation is(with curl):
curl -u admin:admin -X POST -H 'Content-Type: application/json'
-d'{"type":"page","title":"new page",
"ancestors":[{"id":456}], "space":{"key":"TST"},"body":{"storage":
{"value":
"<p>This is a new page</p>","representation":"storage"}}}'
http://localhost:8080/confluence/rest/api/content/ | python -mjson.tool
my json_string is:
{"type":"page","title":"new page","ancestors":[{"id":13533694}, "space":{"key":"SPIELWIESE"},"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}
what is wrong?
1 answer
-
answered 2018-04-17 06:28
Garry
You can send username/password in base64 encoded form as below:
HttpObj.setRequestHeader('Authorization', 'Basic [base64 encoded password here]' );
See also questions close to this topic
-
Array empty after pushes were made in get request in Node.js/Express
I am writing a function calling an API to fetch URLs. These are the steps that I wish to accomplish:
- Parsing in an array of objects (restaurants) as arguments
- For each object, call the Google Search API to get some imageURLs
- Store those imageURLs in an array
- Add an attribute called imageURLs in the array of objects in the arguments
The code is able to log the imageURLs within the GET request, but outside of the request, imageURLs is just an empty array.
var googleSearch = function(restaurants, cb){ console.log("google starts"); const apiKey = google_apiKey; const cseKey = cseID; Array.from(restaurants).forEach(function(restaurant){ var keyWord = restaurant.name + " "+ restaurant.location.city + " "+ restaurant.location.state + " food"; var googleURL = "https://www.googleapis.com/customsearch/v1?key="+ apiKey + "&q="+ keyWord + "&searchType=image" + "&cx=" + cseKey + "&num=7" + "&safe=medium" ; //image URLs of each restaurants to be displayed in the front end var imageURLs = []; request .get(googleURL, { json : true, headers: { 'User-Agent' : 'thaorell' } }) .then(function(response){ Array.from(response.items).forEach(function(item){ imageURLs.push(item.link) }); }) .catch(e => { console.log(e); }) restaurant.imageURLs = imageURLs }) cb(null, restaurants); }
-
Java WebProject Not Running in Apache Tomcat Server
I am running a Java Dynamic WebProject Application .I am running the application in Apache Tomcat V7.0 and Java Version 1.7.045.I have added REST API (Jersey jaxrs.2.27.zip jars in lib folder)
Environmental Variables:
JAVA_HOME:C:\Program Files (x86)\Java\jdk1.7.0_45 JRE_HOME:C:\Program Files (x86)\Java\jdk1.7.0_45\jre classpath:%JAVA_HOME%\lib;%JAVA_HOME%/jre7\lib path :%Java_home%\bin
When i start my application.I get the following error
SEVERE: A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]] at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:188) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) ... 6 more Caused by: java.lang.UnsupportedClassVersionError: org/glassfish/jersey/servlet/init/JerseyServletContainerInitializer : Unsupported major.minor version 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:270) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1689) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:270) at org.apache.catalina.startup.ContextConfig.getServletContainerInitializer(ContextConfig.java:1668) at org.apache.catalina.startup.ContextConfig.getServletContainerInitializers(ContextConfig.java:1652) at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1562) at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1270) at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878) at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:376) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5322) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 6 more
-
Using Mountebank, is it possible for an imposter to perform some logic after returning a response to the client?
My app has a workflow where it calls out to an external service and receives a response. Sometime after that, the external service will eventually call an endpoint in my app. For integration testing, is it possible to setup an imposter with Mountebank to mimic this behavior?
In my research, my best guess is to use an injection and then maybe setTimeout() to later perform the POST request I need to make. However, I'm not sure that this is what Mountebank was intended to do.
Thanks!
-
Facebook Graph Api not returning Page Search although returns Feeds, Media and Posts
I have been using Facebook Graph API for almost an year now but recently since like a month ago there's an empty response to the data array when I request for Facebook Page Search.
Other then searching of facebook pages everything else is working fine, even when I only change the "type" within the Query. Here are my Queries on Graph API Explorer.
This Works:
search?type=place&q=abc&fields=about,fan_count,website
.
This Doesn't:
search?type=page&q=abc&fields=about,fan_count,website
.
I can't figure out the reason why its only happening as the query is fine and doesn't returns any error. Please help me get Facebook Pages Search running again. Thanking You!
-
Asp.NET Core API - Change field names
How can API return customised names?
For example:
<UserInfo> <name>aaaaaa</name> <endpoints> <int>1</int> <int>2</int> </endpoints> </UserInfo>
is generated from code
public class UserInfo { public string name; public int[] endpoints; }
I'd like to return this:
<User name="aaaaaa"> <endpoints> <endpoint>1</endpoint> <endpoint>2</endpoint> </endpoints> </User>
How can I
- Rename UserInfo to User
- Define name as attribute
- Rename fields in endpoints array to
endpoint
?
I've tried using
[DataContract]
and[DataMember]
, but nothing changed. -
How to pass coordinates to OpenStreetMap API in Odoo
I'm trying to use the OpenStreetMap API for passing routing coordinates and get a route between two points. So, what i'm looking for is the API URL, but i haven't found yet. I'm working in Odoo v8. GoogleMaps doesn't work in my country, so that easy alternative is not possible... Pleas does any one had worked with that API in Odoo? Thanks in advances.
-
Autohotkey sends default button action if the cursor is over an inactive window
I wrote the following code in order to remap the 4-th and 5-th mouse buttons to scroll up & scroll down:
Code:
XButton2:: While GetKeyState("XButton2","P") { Send {WheelUp 1} Sleep 120 } return XButton1:: While GetKeyState("XButton1","P") { Send {WheelDown 1} Sleep 120 } return
The problem:
If the cursor is over an active window, everything works.
But, when I click the XButton1 (4-th mouse button) or XButton2 (5-th mouse button) with the cursor over inactive window, sometimes it sends the default action into that window.
For example, if the cursor is over Chrome (inactive) and the active window is Task manager, it will send the default "page back" action instead of specified in the script "scroll down", but when I click on Chrome and make it active, everything works
Question:
Is there a way to just disable the default action? So that if you're not holding the button (
While GetKeyState("XButton1","P")
) it just does nothing? -
Run a AHK function or statement only once, after any member of set of keys is pressed and held down
So in this case I am asking AHK to press shift twice with the following functions.
ShiftPress(delay){ send {Shift Down} Sleep, delay send {Shift Up} Sleep, delay } ShiftPressTwice(delay){ ShiftPress(delay) ShiftPress(delay) }
For this set of keys (Not sure if this is the best way to iterate over a set of keys, only using examples I have found online)
w:: a:: s:: d:: 1:: 2:: 3:: 4:: 5:: Space:: ShiftPressTwice(10) while GetKeyState("Space") { Sleep, 10 } Return
My thought is the above code is bit like switch case fall through, then it should call my function
ShiftPressTwice(delay)
one time, then hit theGetKeyState(key)
loop and sleep then bail. What happens is this seems to run in a endless loop. Please let me know if you have any questions. -
autohotkey: copy file name without Path and Extension
Welcome everyone
The following code frome here: https://autohotkey.com/boards/viewtopic.php?f=5&t=44848
Written by: Odlanir
q:: fileselected := Explorer_GetSelection() SplitPath,fileselected, fn MsgBox % "FileName :`t" fn "`nFullName :`t" fileselected clipboard = % "FileName :`t" fn "`nFullName :`t" fileselected return Explorer_GetSelection(hwnd="") { WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A") WinGetClass class, ahk_id %hwnd% if (process = "explorer.exe") if (class ~= "Progman|WorkerW") { ControlGet, files, List, Selected Col1, SysListView321, ahk_class %class% Loop, Parse, files, `n, `r ToReturn .= A_Desktop "\" A_LoopField "`n" } else if (class ~= "(Cabinet|Explore)WClass") { for window in ComObjCreate("Shell.Application").Windows if (window.hwnd==hwnd) sel := window.Document.SelectedItems for item in sel ToReturn .= item.path "`n" } return Trim(ToReturn,"`n") } return
When you click the Hotkey we get the filename and path for selected files, As the picture appears attached
https://drive.google.com/open?id=1VvPKYrbVQEfrmdB34dUND9HbnXMl0Lr2
my question is: How do I get a list by filename only, Without File Path and File Extension As the picture appears attached
https://drive.google.com/open?id=1rCuLikjqT8Nudipby5Y9MOHTqdozGPYn
Any help would be greatly appreciated.