C# No value from GET Request - c#

I have a WinForms Application in C# and I am trying to get the HTML-Code of a page via a GET-Request with the HTTPS-Protocol, but I am not able to get any value.
I have tried several solutions, but I can not fix this issue on my own.
Here is the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Http;
using System.IO;
namespace sharpFUT
{
public partial class frmShapfut : Form
{
string HTMLCode;
public frmShapfut()
{
InitializeComponent();
}
private async void btnSearch_Click(object sender, EventArgs e)
{
try
{
HTMLCode = await getHTMLCode(tbxPlayerURL.Text);
}
catch (Exception)
{
MessageBox.Show(e.ToString());
}
MessageBox.Show(HTMLCode);
}
private async Task<string> getHTMLCode(string url)
{
var handler = new HttpClientHandler()
{
AllowAutoRedirect = true
};
HttpClient httpClient = new HttpClient(handler);
httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36");
httpClient.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
var result = await httpClient.GetStringAsync(url);
return result;
}
}
}

Related

Xamarin forms detect upi:// URL and open installed UPI applications using PCL

Is there any way to detect upi:// URL in Xamarin forms PCL? I have tried below code but no success yet.
Note: Not looking for android and iOS based solution in this case.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace xamaringformwithIntentUPI
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
MyWebview.Source = "https://payment1.atomtech.in/paynetz/epi/fts?login=1191&pass=NCA#1234&ttype=NBFundTransfer&prodid=NCA&amt=1.00&txncurr=INR&txnscamt=0&clientcode=007&txnid=T2&custacc=1234567890&date=26/06/2018&ru=https://payment.atomtech.in/paynetzclient/ResponseParam.jsp&signature=b8f1c0972cd5f664a5fb41e0b3e5860a3c3bfd66835e5635940cf38245b234063090669ad691b6d6265491bf0510ea07d890530bd5b6309d31c81294b8f122ce&udf2=sagar#gmail.com&udf3=8888888888";
MyWebview.Navigating += Webview_Navigating;
}
private void Webview_Navigating(object sender, WebNavigatingEventArgs e)
{
var url = e.Url;
Console.WriteLine("url detected = " + url);
if (url.StartsWith("upi://"))
{
Console.WriteLine("upi url detected = ");
Console.WriteLine(url);
}
}
}
}

Call WebService With Xamarin Forms (Using Vs 2019)

Trying to Call WebService With Xamarin Forms
getting this error after run it
System.InvalidOperationException: 'A Binding must be configured for this channel factory
This is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace And.Saby8
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Page1 : ContentPage
{
public Page1()
{
InitializeComponent();
login_ico.Source = ImageSource.FromResource("And.Saby8.image.logo.png");
btn_login.Clicked += Btn_login_Clicked;
}
public async void Btn_login_Clicked(object sender, EventArgs e)
{
myapp.myappSoapClient ws = new myapp.myappSoapClient();
login resulto = await ws.loginsAsync(username.Text, password.Text);
if (resulto.validuser)
await Navigation.PushAsync(new MainPage());
else
Device.BeginInvokeOnMainThread(() => {
DisplayAlert("Eror", "", "OK");
});
}
}
}
is there somthing wrong, is there alternative of Completed Event (loginsCompleted witch not available in vs2019)
Can you help me please ?
Thanks.

System.UnauthorizedAccessException: 'Access is denied location UWP

I try to make a simple weather aplication but i get an exception.
I have location activated. I try to run in emulator for phone, not working
the exception
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace TryToMakeWeatherApp
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
var pos = await LocationManage.GetLocation(); //Here i'm geting the error
var lat = pos.Coordinate.Latitude;
var lon = pos.Coordinate.Longitude;
var weather = WeatherMap.GetWeather(lat, lon).ToString();
WeatherTxt.Text = weather;
}
}
}
This is code from MainPage.
And this is the LocationManage class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Geolocation;
namespace TryToMakeWeatherApp
{
class LocationManage
{
public async static Task<Geoposition> GetLocation()
{
var accessStatus = await Geolocator.RequestAccessAsync();
var geolocator = new Geolocator { DesiredAccuracyInMeters = 0 };
var position = await geolocator.GetGeopositionAsync();
return position;
}
}
}
in your package.manifest file have to turn on this capability too

.NET cannot read data from requests

i'm struggling with simplest request handling in C# .NET, whenever i try to read something from request i usually get an Empty value.
Code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class server_save : System.Web.UI.Page
{
private string TXT_PATH = HttpContext.Current.Server.MapPath("files/saved.txt");
protected void Page_Load(object sender, EventArgs e)
{
Response.AppendHeader("Access-Control-Allow-Origin", "*");
string DATA = Request["data"];
try
{
StreamWriter writer = new StreamWriter(TXT_PATH, true, Encoding.Default);
writer.WriteLine(DATA);
writer.Close();
Response.Write(DATA);
}
catch (Exception)
{
Response.Write(TXT_PATH);
}
}
}
http://pastebin.com/nJYBm4mX

What's wrong my windows service on windows 2012?

I have written multiple windows services in one exe & created setup/deployment package to install on destination server (windows 2012). I can see all services in Services & able to start them but it is not performing required action..Weird!!
Program.cs
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new service1(),
new service2(),
new service3()
};
ServiceBase.Run(ServicesToRun);
service1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Configuration;
using System.Net;
using System.Xml;
using System.IO;
namespace MyService
{
partial class service1: ServiceBase
{
public service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
StreamWriter str = new StreamWriter("D:\\temp\\Text1.txt", true);
str.WriteLine("text");
str.Close();
try
{
//more functionality
EventLog.WriteEntry("done", "done desc", EventLogEntryType.Information);
}
}
catch (Exception ex)
{
EventLog.WriteEntry("Error", ex.Message, EventLogEntryType.Error);
}
}
protected override void OnStop()
{
base.OnStop();
}
}
}
When I start service1 manually, it doesn't perform any action..Neither I see text file getting created nor any error/info in event log. What's wrong? Am I missing something wrong???
Appreciate for help!

Categories