johnmelodyme
Had anyone do a http request in Elixir (mint) for GOIP?
I wrote a server-side programme for GOIP sending OTP number to SMS in Ruby I requested it easily, but how do I request it in elixir ?
require "uri"
require "net/http"
otp_number = rand(000000 .. 999999)
puts "Plese Enter A Phone Number: "
user_phone = gets.chomp
url = URI("http://[my-ip-address]/default/en_US/sms_info.html?line=1&action=sms&telnum=#{user_phone}&smscontent=Application your OTP is #{otp_number}&smskey=1162480578")
http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Basic YWRtaW46YWRtaW4="
request["Accept"] = "*/*"
request["Content-Type"] = "application/x-www-form-urlencoded"
request["Content-Length"] = "125"
response = http.request(request)
puts response.read_body
Marked As Solved
johnmelodyme
@NobbZ Many apologies I solved it , at the line
{:ok, conn, request_ref} = Mint.HTTP1.request(conn, "POST", "/default/en_US/sms_info.html&line=1&action=#{action}&telnum=#{telnum}&smscontent=#{smscontent}&smskey=1162480578",
[
{"Authorization", "Basic YWRtaW46YWRtaW4="},
{"Accept", "*/*"},
{"Content-Type", "application/x-www-form-urlencoded"},
{"Content-Length", "125"}
], nil)
which the parametre I stated “nil” which will not give me result. After adjustment it works !
which is now 
{:ok, conn, request_ref} = Mint.HTTP1.request(conn, "POST", "/default/en_US/sms_info.html?",
[
{"Authorization", "Basic YWRtaW46YWRtaW4="},
{"Accept", "*/*"},
{"Content-Type", "application/x-www-form-urlencoded"},
{"Content-Length", "125"}
], "line=1&action=#{action}&telnum=#{telnum}&smscontent=#{smscontent}&smskey=1162480578")
the output is something like this now
{:ok,
%Mint.HTTP1{
buffer: "",
host: "[my-ip-i-cant-show]",
mode: :active,
port: 80,
private: %{},
request: %{
body: nil,
connection: [],
content_length: nil,
data_buffer: [],
headers_buffer: [],
method: "POST",
ref: #Reference<0.1063083407.3741843458.16189>,
state: :status,
status: nil,
transfer_encoding: [],
version: nil
},
requests: {[], []},
scheme_as_string: "http",
socket: #Port<0.6>,
state: :closed,
transport: Mint.Core.Transport.TCP
}}
2
Also Liked
NobbZ
This is just a guess, but I think you need to escape the spaces in the content. Please check how your ruby code actually encodes it and mimic the same behaviour with your elixir code.
Also mint is rather a low-level library as far as I remember, you might want to prefer a higher level library like httpoison, httpotion or tesla.
1
Popular in Questions
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
I would like to know what is the best IDE for elixir development?
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir
iex(2)...
New
Other popular topics
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Hi everyone,
One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New







