How to send post webrequest from javascript used in html loaded a in webview - titanium mobile? - ssl

I need to send post web request from titanium mobile webview.
Created a webview and included the below html code (Upload.html)
<html>
<head>
<script>
function loadXMLDoc()
{
//alert('asdfsf');
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST","https://www.mydomain.com",true);
xmlhttp.send('encrypted image string');
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert('xmlhttp'+xmlhttp.responseText);
  }
}
}
</script>
</head>
<body onload="loadXMLDoc()">
<h1>Sample</h1>
</body></html>
and used in webview as follows:
var webview = Ti.UI.createWebView({
url : 'Upload.html',
height : 100,
width : 100,
top : 0,
left : 0
});
On creating the webview console shows
2013-02-07 17:36:20.906 WebviewSample[6575:1f43f] [WARN] Unable to securely connect to api.appcelerator.net with the latest TLS. Trying again with TLS1.0. It is highly suggested that the server be updated to the latest TLS support.
[ERROR] Analytics error sending request: A connection failure occurred: SSL problem (Possible causes may include a bad/expired/self-signed certificate, clock set to wrong date)

Although the console error may seem to be related to your webview I think it's not.
I think you have analytics enabled for your application and for some reason the SSL session is being rejected (time not correctly configured, etc.).
Disable analytics in your tiapp.xml and this error should not appear again, or try to figure out what is making the SSL connection to be rejected.
Second thought: If you're trying to post to an https domain and you're already having issues with your time config. it probably won't post anything through the webview because the SSL connection is also being rejected for the same reason as the analytics connection.

Related

WebSocket connection to 'wss://tracker.btorrent.xyz/' failed: Error during WebSocket handshake: Unexpected response code: 522 {webtorrent}

Hello fellow homo sapiens, I seem to have reached a dead end here and would require your assistance. I am using webtorrent-hybrid to display a torrent, however when I use client.add to download my torrent, I get this error,
ICE failed, add a TURN server and see about:webrtc for more details 10
Firefox can’t establish a connection to the server at wss://tracker.btorrent.xyz/.
and this is the code if you are curious,
client.add(torrentId, function (torrent) {
var file = torrent.files.find(function (file) {
return file.name.endsWith('.mp4')
})
var info = torrent.ready
console.log(info)
file.appendTo('body')
console.log(file)
// Display the file by adding it to the DOM. Supports video, audio, image, etc. files
})
I would thankful if you could assist me in my problem.

strophe connect openfire error

I input a jid and pwd on a html form, and use Strophe to connect to openfire, but when I press the login button, the xmpp server response is error 302.
I enabled the option on openfire, and restarted it.
var BOSH_SERVICE = 'http://ip:7070/http-bind';
$('#btn-login').click(function() {
if(!connected) {
connection = new Strophe.Connection(BOSH_SERVICE);
connection.connect($("#input-jid").val(), $("#input-pwd").val(), onConnect);
jid = $("#input-jid").val();
}
});
It seems a little harder than to use smack in java because of the network problem?
The problem is in the uri specified in BOSH_SERVICE.
Correct uri is:
http://ip:7070/http-bind/
Pay attention to the / at the bottom of the string.

Unexpected server response (0) while retrieving pdf

We are specifically getting this error when using Amazon ec2 instance. Configuration on aws instance is Tomcat 7, Ubuntu 16.04 and memory is 8gb. It occurs when the user tries to view pdf file. In our application, we are having one functionality where the user can only view PDF file onto browser, but won't be able to download it. PDF file is on the same server. We are using cors minimal configuration. We have tried it locally with Ubuntu and it is working fine.
Code snippet:
var fileSplitContent = fileName.split(".");
if ($('#viewImageOnlyForm')[0] != undefined && $('#viewPdfOnlyForm')[0] != undefined) {
if (fileSplitContent[fileSplitContent.length - 1].toLowerCase() != "pdf") {
$('#imageSource').val(requestURL + $.param(inputData));
$('#viewImageOnlyForm').submit();
} else {
var requestURL = "rest/file/getCapitalRaiseFile?";
$('#pdFSource').val(requestURL + $.param(inputData));
$('#viewPdfOnlyForm').submit();
}
} else {
// pop up download attachment dialog box
downloadIFrame.attr("src", requestURL + $.param(inputData));
}
}
Jan 04, 2017 5:07:31 AM org.glassfish.jersey.server.ServerRuntime$Responder writeResponse
SEVERE: An I/O error has occurred while writing a response message entity to the container output stream.
org.glassfish.jersey.server.internal.process.MappableException: org.apache.catalina.connector.ClientAbortException: java.net.SocketException: Connection reset
Caused by: org.apache.catalina.connector.ClientAbortException: java.net.SocketException: Broken pipe (Write failed)
Depending where you access the document this can be because of you have a download manager installed on your browser. This sometimes causes problems - maybe take a look at your extensions. You should try by disabling downloader manager extension in your browser.

CANDY chat with Openfire : receiving empty response while connecting to a autologin chat room

I finally have the openfire server installed - admittedly noob to XMPP - but I'm getting there :)
I modified the .htaccess & now trying to hit the http://166.xx.xx.xx/candy-chat-candy-ca544b1/example/index.html on my server
The page shows me a "connecting.." message and hangs there.
Here is my setup before I delve into the firebug post/response.
I've modified the example/index.html as such :
$(document).ready(function() {
Candy.init('http://166.xx.xx.xx:7070/http-bind/', {
core: { debug: true },
autojoin: ['Opentalk#conference.166.xx.xx.xx'],
view: { language : 'en' }
});
Candy.Core.connect('166.xx.xx.xx', null, 'Guest'); // Connect anonymously to a specific server
});
In firebug, I see that the response is empty. However the post entry in firebug shows a 200 OK
And firebug complains (which I think is because the response is empty) --> "
XML Parsing Error: no element found Location:
moz-nullprincipal:{80250471-6b20-4144-ad88-92777a926018} Line Number
1, Column 1:
Here is the post
<body rid='3954428912' xmlns='http://jabber.org/protocol/httpbind' to='166.xx.xx.xx' xml:lang='en' wait='60' hold='1' content='text/xml;
charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>
Since my debug is turned on, I see the same message as post :
SENT: <body rid='3954428912' xmlns='http://jabber.org/protocol/httpbind' to='166.xx.xx.xx' xml:lang='en' wait='60' hold='1' content='text/xml;
charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>
Note : The only difference I see in my configuration is the the cross-domain part.
The setup screenshot shown on github has this field empty, while mine has the default entry, I don't know if that is in fact a problem though.
I'm doing something wrong, but can't put a finger as to what..
Any pointers about debugging further would be great !
----------------+++++++++++--------------
Update 2/1 **
Thanks Michael, seems making the changes has taken it a step forward !!
Now I'm getting a grey page instead of hanging at "connecting..".
Seems the connection is now being established. I'm not sure if the PrivacyListError is critical (correct me).
I looked into the candy.js & seems that if the list doesn't exist it'll create one.
The next error does seem critical, since it talks about service unavailable..
Success
SENT: <body rid='2569503371' xmlns='http://jabber.org/protocol/httpbind' sid='b967c785'><iq type='set' id='_session_auth_2' xmlns='jabber:client'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq></body> RECV: <body xmlns='http://jabber.org/protocol/httpbind'><iq xmlns='jabber:client' type='result' id='_session_auth_2' to='b967c785#myservername.com/b967c785'/></body>
[Connection]
Connected [Jabber]
Anonymous login
[Connection] Attached
Success
POST http-bind/ 200 OK 101ms
SENT: <body rid='2569503372' xmlns='http://jabber.org/protocol/httpbind' sid='b967c785'><presence xmlns='jabber:client'/><iq type='get' xmlns='jabber:client'><query xmlns='jabber:iq:private'><storage xmlns='storage:bookmarks'/></query></iq><iq type='get' from='b967c785#myservername.com/b967c785' id='get1' xmlns='jabber:client'><query xmlns='jabber:iq:privacy'><list name='ignore'/></query></iq></body>
RECV: <body xmlns='http://jabber.org/protocol/httpbind'><iq xmlns='jabber:client' type='result' to='b967c785#myservername.com/b967c785'><query xmlns='jabber:iq:private'><storage xmlns='storage:bookmarks'/></query></iq></body>
[Jabber] Bookmarks
Error
POST http-bind/ 200 OK 56ms
SENT: <body rid='2569503373' xmlns='http://jabber.org/protocol/httpbind' sid='b967c785'/>
RECV: <body xmlns='http://jabber.org/protocol/httpbind'><iq xmlns='jabber:client' type='error' id='get1' to='b967c785#myservername.com/b967c785'><query xmlns='jabber:iq:privacy'><list name='ignore'/></query><error code='503' type='cancel'> <service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq></body>
[Jabber] PrivacyListError
Error - this seems more serious
POST http-bind/ 200 OK 74ms
SENT: <body rid='2569503374' xmlns='http://jabber.org/protocol/httpbind'
sid='b967c785'><iq type='set' from='b967c785#myservername.com/b967c785' id='set1'
xmlns='jabber:client'><query xmlns='jabber:iq:privacy'><list name='ignore'><item
action='allow' order='0'/></list></query></iq><iq type='set'
from='b967c785#myservername.com/b967c785' id='set2' xmlns='jabber:client'><query
xmlns='jabber:iq:privacy'><active name='ignore'/></query></iq></body>
RECV: <body xmlns='http://jabber.org/protocol/httpbind'><iq xmlns='jabber:client'
type='error' id='set1' to='b967c785#myservername.com/b967c785'><query
xmlns='jabber:iq:privacy'><list name='ignore'><item action='allow' order='0'/></list>
</query><error code='503' type='cancel'><service-unavailable
xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq></body>
Error - Last one, before it kinda hangs in the there
POST http-bind/ 200 OK 60ms
SENT: <body rid='2569503375' xmlns='http://jabber.org/protocol/httpbind' sid='b967c785'/>
RECV: <body xmlns='http://jabber.org/protocol/httpbind'><iq xmlns='jabber:client'
type='error' id='set2' to='b967c785#myservername.com/b967c785'><query
xmlns='jabber:iq:privacy'><active name='ignore'/></query><error code='503' type='cancel'>
<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq></body>
Last ajax call fired
POST http-bind/ 200 OK 60167ms
SENT: <body rid='2569503376' xmlns='http://jabber.org/protocol/httpbind' sid='b967c785'/>
RECV: <body xmlns='http://jabber.org/protocol/httpbind'/>
POST http-bind/
SENT: <body rid='2569503377' xmlns='http://jabber.org/protocol/httpbind' sid='b967c785'/>
Your http-bind url seems to be wrong as well as the autojoin and the first param of the connect function call.
If you configured the HTTP Proxy configuration correctly, the standard example/index.html should work.
You only need to change/add the autojoin param and change the connect function call.
Regarding the autojoin parameter: You configured a virtualhost on the XMPP server. You need to use this one as the hostname, not the IP. So it would look like autojoin: ['Opentalk#conference.example.com'].
The same applies to the first parameter of connect() you need to provide the virtual hostname of the XMPP Server.

Using Google's ClientLogin Interface via XMLHttpRequest in Javascript

I am trying to learn the ClientLogin Interface detailed on the Account Authentication APIs on Google code website.
I am using Firefox 3.5pre (Shiretoko) and XMLHttpRequest object in Javascript to follow the process. Here's a stripped down version of what I have:
<html>
<head>
<title>Test</title>
<script type="text/javascript">
//<![CDATA[
function update() {
var auth_params = "accountType=HOSTED_OR_GOOGLE&Email=val"
+"&passwd=val&service=cl&source=MMA-Learning";
var request = new XMLHttpRequest();
request.open('POST', 'https://www.google.com/accounts/ClientLogin', true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.setRequestHeader("Content-Length", auth_params.length);
request.setRequestHeader("Connection", "close");
request.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
alert ("Request done");
}
};
try {
request.send( auth_params );
} catch (e) {
alert ("Send Exception:\n"+e);
}
}
//]]>
</script>
</head>
<body>
Authenticate
</body>
</html>
When I click on the Authenticate link, all I get back is a Bad Request response. Examining the request headers, I don't see Content-Type set to application/x-www-form-urlencoded.
I am using Firebug 1.5X to examine the traffic.
For now, all I want to do is generate request mentioned in the Sample Request section and get a response mentioned in the Sample Responses section. If I get there, I want to get some account specific data like, unread Google Reader feeds etc.
I suspect that you've been bitten by Javascript's "same origin" policy. It prevents Javascript, including XmlHttpRequest, from accessing one domain from another. More information is available from Mozilla.
There are hacks to get around this, but I have no idea if they'll work with Google's API.
the 'p' in 'passwd' is a small 'p' instead of a capital 'P'
you probably figured that out tho. When you post and you find the answer, it is always polite if you post the answer as well. This helps the people in the future who will look at your post for information
That 'p' took me two hours to find because i persummed that the code google gave was copied correctely and there was no case mistakes
no point in Internet being full of questions with no answers