Consuming a Ruby on Rails app on my domain server - html

I am running rails version 2.3.2 on my website domain and I am having a huge problem with wrapping my head around how this works:
I have my website running a RoR app on my domain development server. It is just a sample scaffold that allows you to type in your name, zip, state, etc. I am using ruby 1.8.2, and have a mysql server also.
I want to consume this data into my windows phone 7 through SOAP (I don't know if I even have one to begin with), but here is where I have problems.
In using visual studio, it cannot locate my server when i direct it over to my url. It gives the error saying that there was nothing in the correct format.
Maybe I don't have a server running? I want to have the data be parsed out into XML for the phone to consume, but I have no idea how to set this up!
Basically, I have the domain, and the phone, but no knowledge of the steps inbetween.
Can anyone help me get this up and running?

A few things to try:
First - have you actually started the server? eg by running "script/server" ?
You can test that the server is up and running by using "curl" (google for it to install/download" which is a very simple (and very commonly used) application for testing this stuff easily.
if you run curl and type in the url that you'd be accessing via your windows phone... and it responds with something (probably html), then the server is up and running. You can later use CURL to test if it responds to an xml request too.
Second: go look in the controller. See if it has a section such as:
respond_to do |format|
format.html
format.xml { render :xml => #widgets.to_xml }
end
it's the "respond_to" and "xml" bits that matter if you are going to get your system to consume xml. They should be present in every action in your controller. If not - you will have to go a research how to do this for your code - alternatively, using a later version of rails will let you use the up-to-date scaffold generators that should include these as standard.
Third: it is possible that your Windows phone app is just not requesting the resources in xml format and so Rails is returning html (which your SOAP parser won't understand). I don't know how you can check this, but what rails requires is for the HTML-header: "Accept" to be set to "application/xml" or "text/xml"
You can also test this for any given URL with curl by using eg: "curl -H 'Accept: text/xml' 127.0.0.1/myapp" - if it continues to spit out html (and not xml) then obviously it's not producing xml for that URL.

The easiest way to go about this is to simply emit JSON and consume that on your mobile application. Generally you just need to call .to_json on an object and you're half done. SOAP requires a ton of XML overhead that's usually not worth it unless you're already neck-deep in an enterprise application that's overflowing with it.
Updating your Rails stack to 2.3.11 and Ruby 1.8.7 is strongly encouraged as older versions of Rails, as with any application, have vulnerabilities. Ruby 1.8.2 is from around 2005 and is effectively ancient.

Related

How to fix axios.post without using package.json's proxy

The axios.post request doesn't work without proxy.
I am new in react js and using create-react-app
When I use proxy attribute in package.json and give it my http://url:port in my axios.post I start from /api/...
I do not need any config like headers or allow access. And I don't need to stringy data.
My back-end is java using Apache Tomcat and in back-end I have CORS filter that only allows application/json
requests. When I use postman if the header doesn't match , Apache refuses the request by 415 unsupported media type.
The problem begins from where I want to use npm run build. so there is no package.json and I should bring my full url to axios.post's url part : http://url:prot/api/..
Then I removed the proxy part from package.json
Since that I haven't seen any response from java or even it doesn't refuse the request in http monitoring or Apache Log part (in Netbeans)
I did two small things and something changed!
1-Adding JSON.stringfy before data
2-Adding headers Content-Type:Application/json
Now the request is observable in Netbeans (the back-end) BUT the messege is unsupported media type although i have added to axios.post's config(and itself caused the request received )!!!
there is some thing else : when I use the fire fox CORS enable adds on every things goes grate but only with that...
This is my first project. please explain like I'm 5! I do not know anything more!
Or if someone has any better way; is there any way i can use axios.post without package json proxy?

Mobile app to server protocol

I have developed an app that use a RESTful API using JSON:
- Server side: PHP
- Mobile side: JavaScript or AS3 - XHTTPRequest (AJAX)
Each time I request data to server from mobile I send "{user, password, info request}", and I have developed my own algorithm to encrypt these data before sending them.
Probably I can use HTTPS to send data in a safer way, and I can use SESSION info to avoid the need of sending user/password in each request.
This is not the problem, the problem is that I have the sense of being reinventig the wheel because this issue must be solved already in a million ways (almost every app needs info exchange with a server through HTTP/HTTPS).
I have found lots of link in stackoverflow talking about using JSON/REST but no one talking about an specific standard protocol.
I have found other places with info:
http://openmobilealliance.org/
https://core.telegram.org/mtproto
wikipedia: Wireless Application Protocol
But I am not sure about the better way for doing it.
Any sugestion?, any tutorial, specification, example or case of use link?
Thanks a lot.
J. Pablo.
Firebase is one that I've heard of and haven't used yet. https://firebase.google.com/
I am currently building one using JWT and Laravel, and have been pretty happy with it. Using this link as a guide: https://scotch.io/tutorials/role-based-authentication-in-laravel-with-jwt

API kitchen POSTing to drupal service

So I am using http://apikitchen.com/ to debug an issue I am having with a drupal service.
I use: http://vmstage.dop.com/mobile/user/login.json as the URL to test. Method is POST and add two parameters:
username
password
Set the username and password as whatever you like. It will return 401 Unauthorized: Wrong username or password. which is what you should get since you don't know the username or password
I saw they had a mac osx version of this and when I run the exact same thing in their desktop program I get a 406 - Not acceptable.
The reason I am testing in this is because an iPhone app I am working relies on the drupal services to login and I am getting the same thing running through the iPhone emulator.
Back to the API kitchen thing, it works through the browser, but not through their desktop program..makes me think it has something to do with content-type or port. What do you guys think?
I am the author of APIKitchen. I don't think there are any differences between the web and desktop version but if you can provide a sample url with parameters I can quickly look into it.
Generally a 406 error is used to indicate that a request is malformed in some manner. I am not familiar with the tools you are using, but I think you are on the right track in looking for things that might be different between the different requests. You should look at the header differences (including content type). Also, maybe there are some JSON encoding differences between the two different platforms that the API doesn't like.

How to hit a web page programmatically and silently?

I would like to know how can I hit a web page programmatically and silently using C/C++?
I tried ShellExecute (shellapi.h), don't know how to make use of it?
Use the HTTP protocol directly
netcat
curl
wget
HTTP Client Services
On linuxen there are perl implemented CLI commands (GET, PUT, POST), in short: pick one from a vast array; you platform will have tools too.
Simplistic example:
type request.http | netcat mywebserver:80
Where request.http could be as simple as
GET /
(mind the trailing empty lines, which SO helpfully hides)

Null JSON in getJSON response from IIS6, not IIS7? Using MVC2, jQuery, Ajax

New here. I've searched quite a bit for a working solution to my problem, but even though I have found posts with promising titles, none of the solutions have worked.
I am deploying an MVC2 web app to a client's server.
I did my development on Win2k8 Server, but they are running Win2k3 sever.
The app's only purpose is to receive some record ID information as HTTP parameters, check in the database for the status of the given record or records, and then return the status information as a simple string such as "Completed" or "Incomplete" in JSON format.
This getJSON code works fine in the development environment.
Inexplicably to me, on the client's server, the getJSON request receives a null response from the application.
There is no cross-domain action AFAIK... the result is the same from the client's server or from my machine via VPN.
In the MVC model's Json code, a common solution for people is to add the "JsonRequestBehavior.AllowGet" attribute to the Json result being returned. I did this long before trying to deploy it, and as I said, it has worked fine in the dev environment.
Using Firebug, I have watched the same request URL get sent to both my local server and the client server - the response headers from both servers are the same, but the response content from my server is shown as:
{"Result":"No Data"}
Which is what I want.
There is literally no content shown in the response from the client's server..? But the request gets an HTTP 200 code and is recorded as a success in the reponse's status attribute.
The response header content type in both situations is "application/json"
But wait, there is more!
If I manually enter the request to each server in the Firefox nav bar, and hit enter, in both cases it responds with:
{"Result":"No Data"}
Which is what I want. So why can I get the result I want from the MVC app on the client's server only when I hand-enter the request URL in Firefox, but not from the Javascript code?
I have tried forcing different output content types ... using the jQuery ajaxSetup method...
$.ajaxSetup({
async: false,
dataType: 'text'
});
or
$.ajaxSetup({
async: false,
dataType: 'html'
});
and again wtih 'script', and 'json'. I also tried the conversion options such as 'text json' or 'html json' or 'json text' and so forth.
Some of the posts I'm reading, and my gut feeling, though, suggest the problem is not the jQuery code making the request that is at fault... I don't see how the same jQuery request point to a different server running the same app would suddenly cause that server to send back a 'null' value.
By null, I want to be clear... I mean nothing is sent. There is no {} or {null} or any sign of JSON... just blank whiteness of non-existence :P
Even if nobody knows the answer, I would love some input perhaps suggesting where I should focus my sleuthing ... client or server?
If the problem is the server, it seems hard to really know that the MVC stuff is running 100% on the IIS6 server, but in general it seems to work. I have a different MVC app running on the client server which responds to the virtual paths, and generally runs the same as on dev machine.
I have found one thing ... the request headers are somewhat different? The Request Headers sent to the IIS7 setup include an "X-Requested-With: XMLHttpRequest", "referrer" , and "cookie" field/value.
I could guess that the lack of the "X-requested-with: XMLHttpRequest" in the IIS6 request headers is a clue, but I do not see then how the same javascript code pointing at a different server can generate different request headers itself. So how else are those being generated?
The javascript is embedded in an ASP.NET page, btw.
Oooh.. frustration!
Thanks for any input.
Odd Progress ... apparently there is some sort of issue with IIS6 handling the query. Although I have not payed any attention to JSONP, a post elsewhere suggested that sometimes use the "&callback=?" parameter at the end of a .getJSON request URL would force it into GET mode and that worked frequently for problems getting data from the server. So I did that... and it did work, sort of. The proper {"Result":"No Data"} was returned in response to the request... which seems good. However, the way that the JSONP callback works, it generates its own script to do the calling and fetching and interpreting of the incoming JSON. In this case, it interprets the JSON to need a label which it does not have, thus an error is thrown "invalid label" ... there must be some way to hack things to just deliver the JSON, but the whole required use of JSONP callbacks suggests that the server configuration is wrong, right? Or why does it work without JSONP for IIS7 and not IIS6?
Despite my not liking the callback JSONP solution, it appears to work ok. The error is still returned about an invalid label, but that does not appear to stop the remaining javascript from running... and so the application is working with IIS6 now. I have not tested the fix of using the callbacks and JSONP against IIS7 yet, but I expect it will work well enough.
Here is a link to the discussion that lead me to my current solution. I do still hope to find a more elegant solution, however.
NeoWin.net
Are you certain that your App Extension Mappings are set up correct?
Follow this article for running MVC2 on IIS6 and ensure all the different configurations have been done, that's probably the first step before going further and investigating specifics.
I'm really inclined to believe it's related to HTTP Verbs.