• 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

PowerShell  RSS feed

 
Ranch Hand
Posts: 1204
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: 2153
278
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?
 
Isaac Ferguson
Ranch Hand
Posts: 1204
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...
 
Isaac Ferguson
Ranch Hand
Posts: 1204
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?
 
Bartender
Posts: 9494
184
  • 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?
 
Isaac Ferguson
Ranch Hand
Posts: 1204
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
Bartender
Posts: 9494
184
  • 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?
 
Isaac Ferguson
Ranch Hand
Posts: 1204
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
Bartender
Posts: 9494
184
  • 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?
 
Isaac Ferguson
Ranch Hand
Posts: 1204
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
Bartender
Posts: 9494
184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

 
Isaac Ferguson
Ranch Hand
Posts: 1204
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?
 
Isaac Ferguson
Ranch Hand
Posts: 1204
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
Bartender
Posts: 9494
184
  • 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?

 
Isaac Ferguson
Ranch Hand
Posts: 1204
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
Bartender
Posts: 9494
184
  • 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?
 
Isaac Ferguson
Ranch Hand
Posts: 1204
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
 
Isaac Ferguson
Ranch Hand
Posts: 1204
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?

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





 
Stephan van Hulst
Bartender
Posts: 9494
184
  • 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.
 
Isaac Ferguson
Ranch Hand
Posts: 1204
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?
 
Isaac Ferguson
Ranch Hand
Posts: 1204
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?
 
Isaac Ferguson
Ranch Hand
Posts: 1204
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!