added support for https in the post script
This commit is contained in:
		
							parent
							
								
									96b29a1b69
								
							
						
					
					
						commit
						2756cd7a82
					
				
							
								
								
									
										11
									
								
								auth/post.rb
								
								
								
								
							
							
						
						
									
										11
									
								
								auth/post.rb
								
								
								
								
							|  | @ -1,13 +1,14 @@ | ||||||
| require 'net/http' | require 'net/https' | ||||||
| require 'net/http/post/multipart' | require 'net/http/post/multipart' | ||||||
| require 'uri' | require 'uri' | ||||||
| require 'json' | require 'json' | ||||||
| 
 | 
 | ||||||
| # The URL you want to send the POST request to | # The URL you want to send the POST request to | ||||||
| url = URI.parse('http://auth.roysathome.net/auth/login') | url = URI.parse('https://auth.roysathome.net/auth/login') | ||||||
| 
 | 
 | ||||||
| # Create a new Net::HTTP object with the target server | # Create a new Net::HTTP object with the target server | ||||||
| http = Net::HTTP.new(url.host, url.port) | http = Net::HTTP.new(url.host, url.port) | ||||||
|  | http.use_ssl = true | ||||||
| 
 | 
 | ||||||
| # If your server uses HTTPS, you might need to enable SSL | # If your server uses HTTPS, you might need to enable SSL | ||||||
| # http.use_ssl = true | # http.use_ssl = true | ||||||
|  | @ -43,7 +44,7 @@ response_data = JSON.parse(response.body) | ||||||
| reauthentication_token = response_data['token'] | reauthentication_token = response_data['token'] | ||||||
| 
 | 
 | ||||||
| #while true | #while true | ||||||
|     url = URI.parse('http://auth.roysathome.net/auth/reauthenticate') |     url = URI.parse('https://auth.roysathome.net/auth/reauthenticate') | ||||||
|     request = Net::HTTP::Post.new(url.path) |     request = Net::HTTP::Post.new(url.path) | ||||||
| 
 | 
 | ||||||
|     request['Authorization'] = "Bearer #{reauthentication_token}" |     request['Authorization'] = "Bearer #{reauthentication_token}" | ||||||
|  | @ -71,10 +72,11 @@ reauthentication_token = response_data['token'] | ||||||
| file_content = File.read('./example.txt') | file_content = File.read('./example.txt') | ||||||
| 
 | 
 | ||||||
| # Create a URI object for the API endpoint | # Create a URI object for the API endpoint | ||||||
| uri = URI.parse('http://auth.roysathome.net/upload') | uri = URI.parse('https://auth.roysathome.net/upload') | ||||||
| 
 | 
 | ||||||
| # Create a Net::HTTP object | # Create a Net::HTTP object | ||||||
| http = Net::HTTP.new(uri.host, uri.port) | http = Net::HTTP.new(uri.host, uri.port) | ||||||
|  | http.use_ssl = true | ||||||
| 
 | 
 | ||||||
| request = Net::HTTP::Post::Multipart.new( | request = Net::HTTP::Post::Multipart.new( | ||||||
|   uri.path, |   uri.path, | ||||||
|  | @ -91,6 +93,7 @@ response = http.request(request) | ||||||
| 
 | 
 | ||||||
| unless response.code == '200' | unless response.code == '200' | ||||||
|     puts response.code |     puts response.code | ||||||
|  |     puts response.body | ||||||
| else | else | ||||||
|     puts response.body |     puts response.body | ||||||
| end | end | ||||||
		Loading…
	
		Reference in New Issue