I have a personal server and I want to add some new functions to it.It is a Windows server running Windows Server 2019.The core program is wrote by me in c++,but it is just a core and can't access the Internet.It should receive a string from a webpage and return a string to it.My old way is using ASP create a file to storage the string from webpage and use my c++ program to overwrite it.But if the server get two tasks at same time,the result will become a mess.My ISP blocked port 80 so I'm using port 8012 to run my website.My router can't map to many port outside (There also a FTP service and a mail service in the server.) so I can only use the port 8012.What should I do?Should I write a C++ HTTP server?
Server Info:
Service port-inside port-outside software
WEB 80 8012 IIS
FTP 21 21 Serv-U
FTP-pasv 6000-6009 6000-6009 Serv-U
POP3 110 9110
SMTP 25 9025
RemoteDesktop 3389 3389 Windows
I have solved my questions.I am using some AJAX code to add a time sign and random numbers to avoid request crash.
Here are the AJAX code:
function GetValue(id)
{
return document.getElementById(id).value;
}
function SetValue(id,val)
{
document.getElementById(id).value=val;
return;
}
function GetTRValue() //Time-Random value,avoid messing up request
{
var rdm=Math.Random().toString(16);
var dt=new Date();
var time=dt.getTime().toString(10);
var tr=rdm+time;
return tr;
}
function EncodeRequest()
{
var req=new XMLHttpRequest();
req.onreadystatechange=function(){
if(req.readyState==4 && req.status==200)
{
SetValue('code',req.responseText);
}
else if(req.readyState==4 && req.status!=200)
{
alert('Server error:'+req.status);
}
}
req.open('POST','/base/base.asp',true);
req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
req.send('type=encode&code='+GetValue('base')+'&srcstr='+GetValue('str')+'&rdm='+GetTRValue());
return;
}
function DecodeRequest()
{
var qer=new XMLHttpRequest();
qer.onreadystatechange=function(){
if(qer.readyState==4 && qer.status==200)
{
SetValue('str',qer.responseText);
}
else if(qer.readyState==4 && qer.status!=200)
{
alert('Server error:'+qer.status);
}
}
qer.open('POST','/base/base.asp',true);
qer.setRequestHeader('Content-type','application/x-www-form-urlencoded');
qer.send('type=decode&code='+GetValue('base')+'&srcstr='+GetValue('code')+'&rdm='+GetTRValue());
return;
}
In my ASP file,I simply create a folder named the "Time-Random Value",and put request file here.Then wait for responses from C++ program,read it and delete the folder.
In my C++ program, I scan for folders and write responses into the same folder.
Related
I'm using autobahn-js (0.11.2) in a web browser and the crossbar message router (v17.2.1) in the backend.
In case of a network disconnect (e.g. due to poor network) the autobahn-js client can be configured to try to reconnect periodically.
Now in my web app powered by autobahn subscriptions to different WAMP topics are created session.subscribe('my.topic', myhandleevent) dynamically.
Is there a best practice on how to reregister all active subscriptions upon reconnect? Is that maybe configurable even?
I think resubscriptions are not configurable out-of-box. But onopen is fired after reconnect, so placing subscriptions initialization inside it, will do the thing:
var ses;
var onOpenFunctions = [];
function addOnOpenFunction(name) {
onOpenFunctions.push(name);
if (ses !== null) {
window[name]();
}
}
connection.onopen = function (session, details) {
ses = session;
for (var i = 0; i < onOpenFunctions.length; i++) {
window[onOpenFunctions[i]]();
}
};
Then if you want subscribe dynamically you have to do this:
function subscribeTopic() {
session.subscribe('my.topic', myhandleevent)
}
addOnOpenFunction('subscribeTopic');
I am trying to build a Firebase hosted page that will connect to a (Django) HTTP web service using XMLHttpRequest in the below script.
<script>
function UserAction() {
var req = createRequest(); // defined below
// Create the callback functions:
var handleResponse = function (status, response) {
alert("status " + status + " response: " + response)
}
var handleStateChange = function () {
switch (req.readyState) {
case 0 : // UNINITIALIZED
case 1 : // LOADING
case 2 : // LOADED
case 3 : // INTERACTIVE
break;
case 4 : // COMPLETED
alert("case 4" + req.responseType);
handleResponse(req.status, req.responseJson);
break;
default: alert("error");
}
}
req.onreadystatechange = handleStateChange;
req.open("GET", "https://foo.org:/bar/getid/?Id=" + document.getElementById('ID').value, true);
req.send();
function createRequest() {
var result = null;
if (window.XMLHttpRequest) {
// FireFox, Safari, etc.
result = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
// MSIE
window.alert("windows");
result = new ActiveXObject("Microsoft.XMLHTTP");
}
else {
// No known mechanism -- consider aborting the application
window.alert("no known mechanism");
}
return result;
}
}</script>
Using Chrome FireBase throws 404 error. Django server does not register any connection.
Using FireFox FireBase throws 404 error. But Django server throws
'code 400, message Bad HTTP/0.9 request type ('\x16\x03\x01\x00\xcc\x01\x00\x00\xc8\x03\x03\xdf\x04{\x9f\xe4\xb2\xc2ij\x8d\x14\xd5\xaa\xdcu\x14+&\xa4\xa1\xdf\xdc\xd8\x9b?\xea\xbdh\xb8')`
I did find this in the FireBase documentation here, making me think this is not possible. But hopefully I am wrong, or there is a way to do this in development/test, but not production.
SSL only: Firebase Hosting is SSL-only, meaning that content will only
be served over HTTPS. As you are developing your application make sure
that all external resources not hosted on Firebase Hosting are loaded
over SSL (HTTPS), including any external scripts. Most browsers do not
allow users to load "mixed content" (SSL and non-SSL traffic).
thanks
I have installed web app server and now the server is 192.168.1.103 on IIS and i have a sample code from this site https://code.msdn.microsoft.com/office/Building-an-Office-Web-f98650d6/view/Discussions#content
in this sample the appwopiserver in web config is:
"wopihost.wingtip.com:8888/api/wopi/files/"
How can i create api/wopi/files/ directory in my server ? in other words i want to change this code to connect to my server .
here is the code that get the link:
public Link GetLink([FromUri] FileRequest fileRequest)
{
if (ModelState.IsValid)
{
var xml = WebConfigurationManager.AppSettings["appDiscoveryXml"];
var wopiServer = WebConfigurationManager.AppSettings["appWopiServer"];
bool updateEnabled = false;
bool.TryParse(WebConfigurationManager.AppSettings["updateEnabled"], out updateEnabled);
WopiAppHelper wopiHelper = new WopiAppHelper(HostingEnvironment.MapPath(xml), updateEnabled);
var result = wopiHelper.GetDocumentLink(wopiServer + fileRequest.name);
var rv = new Link
{
Url = result
};
return rv;
}
throw new ApplicationException("Invalid ModelState");
}
the final created link to open office in browser in this sample is:
http://owa1.wingtip.com/we/wordeditorframe.aspx?WOPISrc=http%3a%2f%2fwopihost.wingtip.com%3a8888%2fapi%2fwopi%2ffiles%2ftest.docx&access_token=YMDZjBxXlD4%3dlxnjDAq1aib0yGsNDo%2fd0Jm4b5R8eJircFrcaU84fgQ%3d
but i want something like this:
(http:// 192.168.1.103/we/wordeditorframe.aspx?WOPISrc=http%3a%2f%2fwopihost.wingtip.com%3a8888%2fapi%2fwopi%2ffiles%2ftest.docx&access_token=YMDZjBxXlD4%3dlxnjDAq1aib0yGsNDo%2fd0Jm4b5R8eJircFrcaU84fgQ%3d)
You have to replace App_Data\Discovery.xml with an XML you find at http://192.168.1.103/hosting/discovery (your OWA server).
i tried to connect REST web servie from windows phone 8 application.
it was working proberly for weeks but after no change in it I get this generic error :
System.Net.WebException: The remote server returned an error:
NotFound.
i tried to test it by online REST Clients and services works properly
i tried to handle Exception and parse it as webException by this code :
var we = ex.InnerException as WebException;
if (we != null)
{
var resp = we.Response as HttpWebResponse;
response.StatusCode = resp.StatusCode;
and i get no more information and final response code is : "NotFound"
any one have any idea about what may cause this error?
there is already a trusted Certificate implemented on the server . the one who has the server suggested to have a DNS entry for the server, this entry should be at the customer DNS or in the phone hosts file .that what i done and worked for awhile but now it doesn't work however i checked that there is no thing changed
this is sample for Get Request it works proberly on Windwos Store apps :
async Task<object> GetHttps(string uri, string parRequest, Type returnType, params string[] parameters)
{
try
{
string strRequest = ConstructRequest(parRequest, parameters);
string encodedRequest = HttpUtility.UrlEncode(strRequest);
string requestURL = BackEndURL + uri + encodedRequest;
HttpWebRequest request = HttpWebRequest.Create(new Uri(requestURL, UriKind.Absolute)) as HttpWebRequest;
request.Headers["applicationName"] = AppName;
request.Headers["applicationPassword"] = AppPassword;
if (AppVersion > 1)
request.Headers["applicationVersion"] = AppVersion.ToString();
request.Method = "GET";
request.CookieContainer = cookieContainer;
var factory = new TaskFactory();
var getResponseTask = factory.FromAsync<WebResponse>(request.BeginGetResponse, request.EndGetResponse, null);
HttpWebResponse response = await getResponseTask as HttpWebResponse;
// string s = response.GetResponseStream().ToString();
if (response.StatusCode == HttpStatusCode.OK)
{
XmlSerializer serializer = new XmlSerializer(returnType);
object obj = serializer.Deserialize(response.GetResponseStream());
return obj;
}
else
{
var Instance = Activator.CreateInstance(returnType);
(Instance as ResponseBase).NetworkError = true;
(Instance as ResponseBase).StatusCode = response.StatusCode;
return Instance;
}
}
catch (Exception ex)
{
return HandleException(ex, returnType);
}
}
i tried to monitor connections from Emulator and i found this error in connection :
**
Authentication failed because the remote party has closed the
transport stream.
**
You saw the client implement a server side certificate in the service. Did you have that certificate installed on the phone? That can be the cause of the NotFound error. Please, can you try to navigate to the service in the phone or emulator internet explorer prior to testing the app? If you do that, you can see the service working in the emulator/phone internet explorer? Maybe at that point internet explorer ask you about installing the certificate and then you can open your app, and it works.
Also remember if you are testing this in the emulator, every time you close it, the state is lost so you need to repeat the operation of installing the certificate again.
Hope this helps.
If you plan to use SSL in production in general public application (not company-distribution app), you need to ensure your certificate has one of the following root authorities:
SSL root certificates for Windows Phone OS 7.1.
When we had same issue, we purchased SSL certificate from one of those providers and after installing it on server we were able to make HTTPS requests to our services with no problem.
If you have company-distribution app, you can use any certificate from company's Root CA.
I am trying to Post and get a cookie. I am a newbie and this is a learning project for me. My impression is that if you use 'set-cookie' one should be able to see an additional 'set-cookie' in the .toSource. (I am trying to accomplish this on Google Apps Site if that makes a difference.) Am I missing something? Here is my code:
function setGetCookies() {
var payload = {'set-cookie' : 'test'};
var opt2 = {'headers':payload, "method":"post"};
UrlFetchApp.fetch("https://sites.google.com/a/example.com/blacksmith", opt2);
var response = UrlFetchApp.fetch("https://sites.google.com/a/example.com/blacksmith")
var openId = response.getAllHeaders().toSource();
Logger.log(openId)
var AllHeaders = response.getAllHeaders();
for (var prop in AllHeaders) {
if (prop.toLowerCase() == "set-cookie") {
// if there's only one cookie, convert it into an array:
var myArray = [];
if ( Array.isArray(AllHeaders[prop]) ) {
myArray=AllHeaders[prop];
} else {
myArray[0]=AllHeaders[prop];
}
// now process the cookies
myArray.forEach(function(cookie) {
Logger.log(cookie);
});
break;
}
}
}
Thanks in advance! I referenced this to develop the code: Cookie handling in Google Apps Script - How to send cookies in header?
Open to any advice.
When you aren't logged in Google Sites won't set any cookies in the response. UrlFetchApp doesn't pass along your Google cookies, so it will behave as if you are logged out.
First the cookie you want to send whose name is 'test' does not have a value. You should send 'test=somevalue'.
Second I am wondering if you are trying to send the cookie to the googlesite server and ask it to reply with the same cookie you previously sent... ?
I am thinking you are trying to act as a HTTP server beside you are a HTTP client.
As a HTTP client your role is only to send back any cookies that the HTTP server have previously sent to you (respecting the domain, expiration... params).