• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

PowerShell  RSS feed

 
Ranch Hand
Posts: 1327
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

in powershell I am tryin to run this code





Any idea, please?

Regards,
 
Saloon Keeper
Posts: 2504
321
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you expecting the last line to do?  Are you wanting to create a hash table?
 
Angus Ferguson
Ranch Hand
Posts: 1327
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically is a line $hearders which can be called by the Invoke-RestMethod and apply basicAuthentication...the format is json...
 
Angus Ferguson
Ranch Hand
Posts: 1327
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am stuck with this code, it gives a result a null value...







Any idea, please?
 
Saloon Keeper
Posts: 10104
212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PowerShell is not JSON. If you want to write an associative array, you have to use the '=' symbol between keys and values. Also, you wrote your Content-Type header as a single key without a value.

In your new snippet, $result doesn't get the NULL value. Either Exception or Response is NULL, likely Response.

Why do you assume that Exception has a Response?
 
Angus Ferguson
Ranch Hand
Posts: 1327
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I updated the script using "=" for pairs key value



 
Stephan van Hulst
Saloon Keeper
Posts: 10104
212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well yeah, how does it know where one key-value pair ends and the next key-value pair starts?
 
Angus Ferguson
Ranch Hand
Posts: 1327
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean code is similar to this?

 
Stephan van Hulst
Saloon Keeper
Posts: 10104
212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I mean how should PowerShell know where the Authorization pair ends, and where the Content-Type pair starts? Have you looked up the syntax for defining an associative array in PowerShell?
 
Angus Ferguson
Ranch Hand
Posts: 1327
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the best syntax I found on the net.






Any idea, please?
 
Stephan van Hulst
Saloon Keeper
Posts: 10104
212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Why do you assume that Exception has a Response?

 
Angus Ferguson
Ranch Hand
Posts: 1327
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was getting an exception like it is NULL ...now it is gone--

Now I moified the code like this and it makes the POST properly



Now I would like to make a GET and bring all the news I have in my local database. I am using the previous code but with this query  but it fails...




The error in Powershell is



Which parameter is wrong, please?
 
Angus Ferguson
Ranch Hand
Posts: 1327
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And for delete I use this uri




I get the error:



I am looping over it on Google but I dont find a solution...
 
Stephan van Hulst
Saloon Keeper
Posts: 10104
212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You keep asking that question and I keep giving you the same answer.

Stephan van Hulst wrote:Why do you assume that Exception has a Response?

 
Angus Ferguson
Ranch Hand
Posts: 1327
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you elaborate a little bit over it, please?
 
Stephan van Hulst
Saloon Keeper
Posts: 10104
212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You get an exception because you dereference NULL in your catch clause. Likely Response is NULL, and you try to call GetResponseStream() on it. How do you know that Exception has a Response member? Don't you think that any of the statements before the call to Invoke-RestMethod could have thrown an exception?
 
Angus Ferguson
Ranch Hand
Posts: 1327
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had an echo $response = Invoke-RestMethod ....I removed the echo and it works properly now
 
Angus Ferguson
Ranch Hand
Posts: 1327
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the DELETE



This one shows the same error, it goes to the catch I just wrote an echo there. The thing is what is wrong with the URL?

 
Angus Ferguson
Ranch Hand
Posts: 1327
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For GET paramenters error.....





 
Stephan van Hulst
Saloon Keeper
Posts: 10104
212
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know, it completely depends on the web service you're trying to send the request to. Do you have access to the source code? In that case it might be easier to debug the web service than the client script.
 
Angus Ferguson
Ranch Hand
Posts: 1327
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a .ps1 file. It is a DELETE uri to  a service.

I would like to pass a parameter from Java and that it could be retrieved from the .ps1 file in order to happend it to the end of the uri (personid)

Any idea, please?
 
Angus Ferguson
Ranch Hand
Posts: 1327
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean like this



I tried this:



But it works as if the name of the ps1 would happend the string, not that the variables can be retrieved from the ps1 itself. Anyone knows how to do it,please?
 
Angus Ferguson
Ranch Hand
Posts: 1327
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When debugging I get this:



of course this is the error


because the file name it is "D:/delete.ps143120", instead of "D:/delete.ps1". I am trying to pass "43120" to the file as a parameter which could retrieve from within the .ps1
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!