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
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Hello everyone,
I try to use an Javascript Event Handler in my root.html.leex file.
Therefore I created a function in the app.js file: ...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
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
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
Other popular topics
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









